]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: no need to validate substituted instances
authorRobert Findley <rfindley@google.com>
Mon, 16 Aug 2021 20:03:59 +0000 (16:03 -0400)
committerRobert Findley <rfindley@google.com>
Fri, 20 Aug 2021 18:45:13 +0000 (18:45 +0000)
This is a straightforward port of CL 342150 to go/types.

Change-Id: I7363e4642ade7ab30ca822a2be71f4d2804cc4a9
Reviewed-on: https://go-review.googlesource.com/c/go/+/342669
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/subst.go

index da0578ff5c0f294377a5f702221871ad584519b2..e47d20774fe6c32aa8cb4d4666af5ac4da818e3e 100644 (file)
@@ -228,10 +228,15 @@ func (subst *subster) typ(typ Type) Type {
                        return named
                }
 
-               // create a new named type and populate typMap to avoid endless recursion
+               // Create a new named type and populate typMap to avoid endless recursion.
+               // The position used here is irrelevant because validation only occurs on t
+               // (we don't call validType on named), but we use subst.pos to help with
+               // debugging.
                tname := NewTypeName(subst.pos, t.obj.pkg, t.obj.name, nil)
                t.load()
-               named := subst.check.newNamed(tname, t.orig, t.underlying, t.TParams(), t.methods) // method signatures are updated lazily
+               // It's ok to provide a nil *Checker because the newly created type
+               // doesn't need to be (lazily) expanded; it's expanded below.
+               named := (*Checker)(nil).newNamed(tname, t.orig, nil, t.tparams, t.methods) // t is loaded, so tparams and methods are available
                named.targs = newTArgs
                subst.typMap[h] = named
                t.expand(subst.typMap) // must happen after typMap update to avoid infinite recursion
@@ -241,7 +246,7 @@ func (subst *subster) typ(typ Type) Type {
                named.underlying = subst.typOrNil(t.underlying)
                dump(">>> underlying: %v", named.underlying)
                assert(named.underlying != nil)
-               named.fromRHS = named.underlying // for cycle detection (Checker.validType)
+               named.fromRHS = named.underlying // for consistency, though no cycle detection is necessary
 
                return named