aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/subst.go
diff options
context:
space:
mode:
authorRobert Findley <rfindley@google.com>2021-08-13 15:03:14 -0400
committerRobert Findley <rfindley@google.com>2021-08-18 22:16:08 +0000
commit805d38a3529918a708875b068ccee46a7edcead0 (patch)
treeb72068ba0672bef3a2c0397b023cfdd054525a48 /src/cmd/compile/internal/types2/subst.go
parentc2bd9ee2dbec88d4fd1b21aefa21cd988d01b880 (diff)
downloadgo-805d38a3529918a708875b068ccee46a7edcead0.tar.gz
go-805d38a3529918a708875b068ccee46a7edcead0.zip
cmd/compile/internal/types2: no need to validate substituted instances
When substituting a type instance, we rely on the instance being expanded and do not call validType, so there is need to depend on subster.pos for error reporting or to use subst.check for creating the new Named type. Errors will be reported for the unsubstituted instance. This is a superficial change, but justifies some later simplification where we don't have access to pos or check. Change-Id: I1f3f12aa245d821512c6242ad829c940f20afae4 Reviewed-on: https://go-review.googlesource.com/c/go/+/342150 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/types2/subst.go')
-rw-r--r--src/cmd/compile/internal/types2/subst.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/types2/subst.go b/src/cmd/compile/internal/types2/subst.go
index ed3fd654a0..2c0fc6e391 100644
--- a/src/cmd/compile/internal/types2/subst.go
+++ b/src/cmd/compile/internal/types2/subst.go
@@ -222,10 +222,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
@@ -235,7 +240,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