]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: fail early on unexpected types2.Invalid
authorMatthew Dempsky <mdempsky@google.com>
Tue, 3 Aug 2021 01:01:46 +0000 (18:01 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 3 Aug 2021 02:42:15 +0000 (02:42 +0000)
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 <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/noder/writer.go

index 07d4363f89816d2950029e7ddab4346d42e66d95..eb1db623b4a529b16381a59879cddde6d64117c6 100644 (file)
@@ -282,18 +282,22 @@ 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
-               }
 
-               // Handle "byte" and "rune" as references to their TypeName.
-               obj := types2.Universe.Lookup(typ.Name())
-               assert(obj.Type() == typ)
+               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)
+                       w.code(typeNamed)
+                       w.obj(obj, nil)
+               }
 
        case *types2.Named:
                // Type aliases can refer to uninstantiated generic types, so we