From 1b193598b3a4ad3138626ca97bca752e9e63b21c Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 2 Aug 2021 18:01:46 -0700 Subject: [PATCH] [dev.typeparams] cmd/compile: fail early on unexpected types2.Invalid In unified IR, fail right away if we find a types2.Invalid while writing out the package. This provides a clearer error message for https://github.com/golang/go/issues/25838#issuecomment-448746670. Updates #25838. Change-Id: I6902fdd891fc31bbb832b6fdba00eca301282409 Reviewed-on: https://go-review.googlesource.com/c/go/+/338973 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/noder/writer.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/cmd/compile/internal/noder/writer.go b/src/cmd/compile/internal/noder/writer.go index 07d4363f898..eb1db623b4a 100644 --- a/src/cmd/compile/internal/noder/writer.go +++ b/src/cmd/compile/internal/noder/writer.go @@ -282,19 +282,23 @@ func (pw *pkgWriter) typIdx(typ types2.Type, dict *writerDict) typeInfo { base.Fatalf("unexpected type: %v (%T)", typ, typ) case *types2.Basic: - if kind := typ.Kind(); types2.Typ[kind] == typ { + switch kind := typ.Kind(); { + case kind == types2.Invalid: + base.Fatalf("unexpected types2.Invalid") + + case types2.Typ[kind] == typ: w.code(typeBasic) w.len(int(kind)) - break + + default: + // Handle "byte" and "rune" as references to their TypeName. + obj := types2.Universe.Lookup(typ.Name()) + assert(obj.Type() == typ) + + w.code(typeNamed) + w.obj(obj, nil) } - // Handle "byte" and "rune" as references to their TypeName. - obj := types2.Universe.Lookup(typ.Name()) - assert(obj.Type() == typ) - - w.code(typeNamed) - w.obj(obj, nil) - case *types2.Named: // Type aliases can refer to uninstantiated generic types, so we // might see len(TParams) != 0 && len(TArgs) == 0 here.