aboutsummaryrefslogtreecommitdiff
path: root/src/go/types/subst.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/go/types/subst.go')
-rw-r--r--src/go/types/subst.go31
1 files changed, 7 insertions, 24 deletions
diff --git a/src/go/types/subst.go b/src/go/types/subst.go
index 3491541dcb..16aafd622e 100644
--- a/src/go/types/subst.go
+++ b/src/go/types/subst.go
@@ -52,24 +52,12 @@ func (check *Checker) subst(pos token.Pos, typ Type, smap substMap, env *Environ
}
// general case
- var subst subster
- subst.pos = pos
- subst.smap = smap
-
- if check != nil {
- subst.check = check
- if env == nil {
- env = check.conf.Environment
- }
- }
- if env == nil {
- // If we don't have a *Checker and its global type map,
- // use a local version. Besides avoiding duplicate work,
- // the type map prevents infinite recursive substitution
- // for recursive types (example: type T[P any] *T[P]).
- env = NewEnvironment()
+ subst := subster{
+ pos: pos,
+ smap: smap,
+ check: check,
+ env: check.bestEnv(env),
}
- subst.env = env
return subst.typ(typ)
}
@@ -227,11 +215,8 @@ func (subst *subster) typ(typ Type) Type {
// 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.
- named := subst.check.instance(subst.pos, t.orig, newTArgs, subst.env).(*Named)
- // TODO(rfindley): we probably don't need to resolve here. Investigate if
- // this can be removed.
- named.resolve(subst.env)
- assert(named.underlying != nil)
+ t.orig.resolve(subst.env)
+ return subst.check.instance(subst.pos, t.orig, newTArgs, subst.env)
// Note that if we were to expose substitution more generally (not just in
// the context of a declaration), we'd have to substitute in
@@ -239,8 +224,6 @@ func (subst *subster) typ(typ Type) Type {
//
// But this is unnecessary for now.
- return named
-
case *TypeParam:
return subst.smap.lookup(t)