aboutsummaryrefslogtreecommitdiff
path: root/src/go/types/instance.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/go/types/instance.go')
-rw-r--r--src/go/types/instance.go29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/go/types/instance.go b/src/go/types/instance.go
index 5e0447b434..1223c9f6f1 100644
--- a/src/go/types/instance.go
+++ b/src/go/types/instance.go
@@ -8,34 +8,37 @@ package types
import "go/token"
-// instance holds a Checker along with syntactic information
-// information, for use in lazy instantiation.
+// instance holds position information for use in lazy instantiation.
+//
+// TODO(rfindley): come up with a better name for this type, now that its usage
+// has changed.
type instance struct {
- check *Checker
pos token.Pos // position of type instantiation; for error reporting only
posList []token.Pos // position of each targ; for error reporting only
}
-// complete ensures that the underlying type of n is instantiated.
+// expand ensures that the underlying type of n is instantiated.
// The underlying type will be Typ[Invalid] if there was an error.
// TODO(rfindley): expand would be a better name for this method, but conflicts
// with the existing concept of lazy expansion. Need to reconcile this.
-func (n *Named) complete() {
- if n.instance != nil && len(n.targs) > 0 && n.underlying == nil {
- check := n.instance.check
- inst := check.instantiate(n.instance.pos, n.orig.underlying, n.TParams().list(), n.targs, n.instance.posList)
+func (n *Named) expand() {
+ if n.instance != nil {
+ // n must be loaded before instantiation, in order to have accurate
+ // tparams. This is done implicitly by the call to n.TParams, but making it
+ // explicit is harmless: load is idempotent.
+ n.load()
+ inst := n.check.instantiate(n.instance.pos, n.orig.underlying, n.TParams().list(), n.targs, n.instance.posList)
n.underlying = inst
n.fromRHS = inst
- n.methods = n.orig.methods
+ n.instance = nil
}
}
-// expand expands a type instance into its instantiated
-// type and leaves all other types alone. expand does
-// not recurse.
+// expand expands uninstantiated named types and leaves all other types alone.
+// expand does not recurse.
func expand(typ Type) Type {
if t, _ := typ.(*Named); t != nil {
- t.complete()
+ t.expand()
}
return typ
}