if len(fields) == 0 {
return types.Types[types.TINTER] // empty interface
}
- return types.NewInterface(tpkg, fields)
+ return types.NewInterface(tpkg, fields, false)
}
func (r *reader) structType() *types.Type {
cond := ir.NewBinaryExpr(pos, ir.ONE, want, got)
typed(types.Types[types.TBOOL], cond)
panicArg := ir.NewNilExpr(pos)
- typed(types.NewInterface(types.LocalPkg, nil), panicArg)
+ typed(types.NewInterface(types.LocalPkg, nil, false), panicArg)
then := ir.NewUnaryExpr(pos, ir.OPANIC, panicArg)
then.SetTypecheck(1)
x := ir.NewIfStmt(pos, cond, []ir.Node{then}, nil)
methods[i] = types.NewField(g.pos(m), g.selector(m), mtyp)
}
- return types.NewInterface(g.tpkg(typ), append(embeddeds, methods...))
+ return types.NewInterface(g.tpkg(typ), append(embeddeds, methods...), typ.IsImplicit())
case *types2.TypeParam:
// Save the name of the type parameter in the sym of the type.
fldt := mkFuncType(types.FakeRecvType(), []*types.Type{},
[]*types.Type{types.Types[types.TSTRING]})
field := types.NewField(src.NoXPos, typecheck.Lookup("F"), fldt)
- nei := types.NewInterface(types.LocalPkg, []*types.Field{field})
+ nei := types.NewInterface(types.LocalPkg, []*types.Field{field}, false)
i16 := types.Types[types.TINT16]
tb := types.Types[types.TBOOL]
s1 := mkstruct([]*types.Type{i16, i16, tb})
return types.Types[types.TINTER]
}
- t := types.NewInterface(r.currPkg, append(embeddeds, methods...))
+ t := types.NewInterface(r.currPkg, append(embeddeds, methods...), false)
// Ensure we expand the interface in the frontend (#25055).
types.CheckSize(t)
// For an empty interface, we need to return a new type,
// since it may now be fully instantiated (HasTParam
// becomes false).
- return types.NewInterface(t.Pkg(), nil)
+ return types.NewInterface(t.Pkg(), nil, false)
}
return t
}
}
}
if newfields != nil {
- return types.NewInterface(t.Pkg(), newfields)
+ return types.NewInterface(t.Pkg(), newfields, false)
}
return t
}
methods := tcFields(n.Methods, nil)
base.Pos = lno
- n.SetOTYPE(types.NewInterface(types.LocalPkg, methods))
+ n.SetOTYPE(types.NewInterface(types.LocalPkg, methods, false))
return n
}
{Forward{}, 20, 32},
{Func{}, 28, 48},
{Struct{}, 16, 32},
- {Interface{}, 4, 8},
+ {Interface{}, 8, 16},
{Chan{}, 8, 16},
{Array{}, 12, 16},
{FuncArgs{}, 4, 8},
// Interface contains Type fields specific to interface types.
type Interface struct {
- pkg *Pkg
+ pkg *Pkg
+ implicit bool
}
// Typeparam contains Type fields specific to typeparam types.
// NewInterface returns a new interface for the given methods and
// embedded types. Embedded types are specified as fields with no Sym.
-func NewInterface(pkg *Pkg, methods []*Field) *Type {
+func NewInterface(pkg *Pkg, methods []*Field, implicit bool) *Type {
t := newType(TINTER)
t.SetInterface(methods)
for _, f := range methods {
t.SetBroke(true)
}
t.extra.(*Interface).pkg = pkg
+ t.extra.(*Interface).implicit = implicit
return t
}
return t.extra.(*Typeparam).bound
}
+// IsImplicit reports whether an interface is implicit (i.e. elided from a type
+// parameter constraint).
+func (t *Type) IsImplicit() bool {
+ t.wantEtype(TINTER)
+ return t.extra.(*Interface).implicit
+}
+
// NewUnion returns a new union with the specified set of terms (types). If
// tildes[i] is true, then terms[i] represents ~T, rather than just T.
func NewUnion(terms []*Type, tildes []bool) *Type {
}
Types[TANY] = newType(TANY)
- Types[TINTER] = NewInterface(LocalPkg, nil)
+ Types[TINTER] = NewInterface(LocalPkg, nil, false)
defBasic := func(kind Kind, pkg *Pkg, name string) *Type {
typ := newType(kind)
if base.Flag.G > 0 {
DeferCheckSize()
AnyType = defBasic(TFORW, BuiltinPkg, "any")
- AnyType.SetUnderlying(NewInterface(NoPkg, []*Field{}))
+ AnyType.SetUnderlying(NewInterface(NoPkg, []*Field{}, false))
ResumeCheckSize()
}
NewField(src.NoXPos, nil, Types[TSTRING]),
})
method := NewField(src.NoXPos, LocalPkg.Lookup("Error"), sig)
- return NewInterface(NoPkg, []*Field{method})
+ return NewInterface(NoPkg, []*Field{method}, false)
}
func makeComparableInterface() *Type {
sig := NewSignature(NoPkg, FakeRecv(), nil, nil, nil)
method := NewField(src.NoXPos, LocalPkg.Lookup("=="), sig)
- return NewInterface(NoPkg, []*Field{method})
+ return NewInterface(NoPkg, []*Field{method}, false)
}