diff options
Diffstat (limited to 'src/cmd/compile/internal/types2/interface.go')
-rw-r--r-- | src/cmd/compile/internal/types2/interface.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/types2/interface.go b/src/cmd/compile/internal/types2/interface.go index e57158d2d50..340df51524b 100644 --- a/src/cmd/compile/internal/types2/interface.go +++ b/src/cmd/compile/internal/types2/interface.go @@ -11,6 +11,7 @@ import "cmd/compile/internal/syntax" // An Interface represents an interface type. type Interface struct { + check *Checker // for error reporting; nil once type set is computed obj *TypeName // corresponding declared object; or nil (for better error messages) methods []*Func // ordered list of explicitly declared methods embeddeds []Type // ordered list of explicitly embedded elements @@ -21,7 +22,7 @@ type Interface struct { } // typeSet returns the type set for interface t. -func (t *Interface) typeSet() *_TypeSet { return computeInterfaceTypeSet(nil, nopos, t) } +func (t *Interface) typeSet() *_TypeSet { return computeInterfaceTypeSet(t.check, nopos, t) } // emptyInterface represents the empty interface var emptyInterface = Interface{complete: true, tset: &topTypeSet} @@ -198,7 +199,7 @@ func (check *Checker) interfaceType(ityp *Interface, iface *syntax.InterfaceType } // All methods and embedded elements for this interface are collected; - // i.e., this interface is may be used in a type set computation. + // i.e., this interface may be used in a type set computation. ityp.complete = true if len(ityp.methods) == 0 && len(ityp.embeddeds) == 0 { @@ -214,7 +215,15 @@ func (check *Checker) interfaceType(ityp *Interface, iface *syntax.InterfaceType // Compute type set with a non-nil *Checker as soon as possible // to report any errors. Subsequent uses of type sets will use // this computed type set and won't need to pass in a *Checker. - check.later(func() { computeInterfaceTypeSet(check, iface.Pos(), ityp) }) + // + // Pin the checker to the interface type in the interim, in case the type set + // must be used before delayed funcs are processed (see issue #48234). + // TODO(rfindley): clean up use of *Checker with computeInterfaceTypeSet + ityp.check = check + check.later(func() { + computeInterfaceTypeSet(check, iface.Pos(), ityp) + ityp.check = nil + }) } func flattenUnion(list []syntax.Expr, x syntax.Expr) []syntax.Expr { |