return -1
}
+// rhs returns [Named.fromRHS].
+//
+// In debug mode, it also asserts that n is in an appropriate state.
+func (n *Named) rhs() Type {
+ if debug {
+ assert(n.stateHas(lazyLoaded | unpacked))
+ }
+ return n.fromRHS
+}
+
// Underlying returns the [underlying type] of the named type t, resolving all
// forwarding declarations. Underlying types are never Named, TypeParam, or
// Alias types.
// The gccimporter depends on writing a nil underlying via NewNamed and
// immediately reading it back. Rather than putting that in Named.under
// and complicating things there, we just check for that special case here.
- if n.fromRHS == nil {
+ if n.rhs() == nil {
assert(n.allowNilRHS)
if n.allowNilUnderlying {
return nil
t.mu.Lock()
defer t.mu.Unlock()
- assert(t.fromRHS != nil || t.allowNilRHS)
- rhs = t.fromRHS
+ assert(t.rhs() != nil || t.allowNilRHS)
+ rhs = t.rhs()
default:
u = rhs // any type literal works
}
assert(!n.stateHas(unpacked))
- assert(n.inst.orig.stateHas(unpacked | lazyLoaded))
+ assert(n.inst.orig.stateHas(lazyLoaded | unpacked))
if n.inst.ctxt == nil {
n.inst.ctxt = NewContext()
ctxt = check.context()
}
- rhs = check.subst(n.obj.pos, orig.fromRHS, m, n, ctxt)
+ rhs = check.subst(n.obj.pos, orig.rhs(), m, n, ctxt)
// TODO(markfreeman): Can we handle this in substitution?
// If the RHS is an interface, we must set the receiver of interface methods
if methods, copied := replaceRecvType(iface.methods, orig, n); copied {
// If the RHS doesn't use type parameters, it may not have been
// substituted; we need to craft a new interface first.
- if iface == orig.fromRHS {
+ if iface == orig.rhs() {
assert(iface.complete) // otherwise we are copying incomplete data
crafted := check.newInterface()
// Every type added to nest is also added to path; thus every type that is in nest
// must also be in path (invariant). But not every type in path is in nest, since
// nest may be pruned (see below, *TypeParam case).
- if !check.validType0(pos, t.Origin().fromRHS, append(nest, t), append(path, t)) {
+ t.Origin().unpack()
+ if !check.validType0(pos, t.Origin().rhs(), append(nest, t), append(path, t)) {
return false
}
return -1
}
+// rhs returns [Named.fromRHS].
+//
+// In debug mode, it also asserts that n is in an appropriate state.
+func (n *Named) rhs() Type {
+ if debug {
+ assert(n.stateHas(lazyLoaded | unpacked))
+ }
+ return n.fromRHS
+}
+
// Underlying returns the [underlying type] of the named type t, resolving all
// forwarding declarations. Underlying types are never Named, TypeParam, or
// Alias types.
// The gccimporter depends on writing a nil underlying via NewNamed and
// immediately reading it back. Rather than putting that in Named.under
// and complicating things there, we just check for that special case here.
- if n.fromRHS == nil {
+ if n.rhs() == nil {
assert(n.allowNilRHS)
if n.allowNilUnderlying {
return nil
t.mu.Lock()
defer t.mu.Unlock()
- assert(t.fromRHS != nil || t.allowNilRHS)
- rhs = t.fromRHS
+ assert(t.rhs() != nil || t.allowNilRHS)
+ rhs = t.rhs()
default:
u = rhs // any type literal works
}
assert(!n.stateHas(unpacked))
- assert(n.inst.orig.stateHas(unpacked | lazyLoaded))
+ assert(n.inst.orig.stateHas(lazyLoaded | unpacked))
if n.inst.ctxt == nil {
n.inst.ctxt = NewContext()
ctxt = check.context()
}
- rhs = check.subst(n.obj.pos, orig.fromRHS, m, n, ctxt)
+ rhs = check.subst(n.obj.pos, orig.rhs(), m, n, ctxt)
// TODO(markfreeman): Can we handle this in substitution?
// If the RHS is an interface, we must set the receiver of interface methods
if methods, copied := replaceRecvType(iface.methods, orig, n); copied {
// If the RHS doesn't use type parameters, it may not have been
// substituted; we need to craft a new interface first.
- if iface == orig.fromRHS {
+ if iface == orig.rhs() {
assert(iface.complete) // otherwise we are copying incomplete data
crafted := check.newInterface()
// Every type added to nest is also added to path; thus every type that is in nest
// must also be in path (invariant). But not every type in path is in nest, since
// nest may be pruned (see below, *TypeParam case).
- if !check.validType0(pos, t.Origin().fromRHS, append(nest, t), append(path, t)) {
+ t.Origin().unpack()
+ if !check.validType0(pos, t.Origin().rhs(), append(nest, t), append(path, t)) {
return false
}