Commit cd016af6 authored by Robert Griesemer's avatar Robert Griesemer

go/types: rename NewInterface2 to NewInterfaceType

NewInterface2 was introduced with https://go-review.googlesource.com/114317
which fixed #25301. Changed the name to NewInterfaceType to better match
Go naming styles, per discussion with @josharian, @iant, et al.

Change-Id: Ifa4708a5efd4f708295b33c3d20fdc5812e1b4fc
Reviewed-on: https://go-review.googlesource.com/120875Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 8997ec1c
...@@ -437,7 +437,7 @@ pkg debug/pe, const IMAGE_FILE_MACHINE_ARM64 = 43620 ...@@ -437,7 +437,7 @@ pkg debug/pe, const IMAGE_FILE_MACHINE_ARM64 = 43620
pkg debug/pe, const IMAGE_FILE_MACHINE_ARM64 ideal-int pkg debug/pe, const IMAGE_FILE_MACHINE_ARM64 ideal-int
pkg go/ast, type CompositeLit struct, Incomplete bool pkg go/ast, type CompositeLit struct, Incomplete bool
pkg go/token, method (*File) AddLineColumnInfo(int, string, int, int) pkg go/token, method (*File) AddLineColumnInfo(int, string, int, int)
pkg go/types, func NewInterface2([]*Func, []Type) *Interface pkg go/types, func NewInterfaceType([]*Func, []Type) *Interface
pkg go/types, method (*Interface) EmbeddedType(int) Type pkg go/types, method (*Interface) EmbeddedType(int) Type
pkg go/types, method (*Var) Embedded() bool pkg go/types, method (*Var) Embedded() bool
pkg net, method (*ListenConfig) Listen(context.Context, string, string) (Listener, error) pkg net, method (*ListenConfig) Listen(context.Context, string, string) (Listener, error)
......
...@@ -600,7 +600,7 @@ func (p *parser) parseInterfaceType(pkg *types.Package) types.Type { ...@@ -600,7 +600,7 @@ func (p *parser) parseInterfaceType(pkg *types.Package) types.Type {
} }
p.expect('}') p.expect('}')
return types.NewInterface2(methods, embeddeds) return types.NewInterfaceType(methods, embeddeds)
} }
// PointerType = "*" ("any" | Type) . // PointerType = "*" ("any" | Type) .
......
...@@ -536,7 +536,7 @@ func (p *importer) typ(parent *types.Package, tname *types.Named) types.Type { ...@@ -536,7 +536,7 @@ func (p *importer) typ(parent *types.Package, tname *types.Named) types.Type {
embeddeds = append(embeddeds, p.typ(parent, nil)) embeddeds = append(embeddeds, p.typ(parent, nil))
} }
t := types.NewInterface2(p.methodList(parent, tname), embeddeds) t := types.NewInterfaceType(p.methodList(parent, tname), embeddeds)
p.interfaceList = append(p.interfaceList, t) p.interfaceList = append(p.interfaceList, t)
if p.trackAllTypes { if p.trackAllTypes {
p.typList[n] = t p.typList[n] = t
......
...@@ -535,7 +535,7 @@ func (r *importReader) doType(base *types.Named) types.Type { ...@@ -535,7 +535,7 @@ func (r *importReader) doType(base *types.Named) types.Type {
methods[i] = types.NewFunc(mpos, r.currPkg, mname, msig) methods[i] = types.NewFunc(mpos, r.currPkg, mname, msig)
} }
typ := types.NewInterface2(methods, embeddeds) typ := types.NewInterfaceType(methods, embeddeds)
r.p.interfaceList = append(r.p.interfaceList, typ) r.p.interfaceList = append(r.p.interfaceList, typ)
return typ return typ
} }
......
...@@ -260,7 +260,7 @@ var markComplete = make([]*Func, 0) ...@@ -260,7 +260,7 @@ var markComplete = make([]*Func, 0)
// NewInterface takes ownership of the provided methods and may modify their types by setting // NewInterface takes ownership of the provided methods and may modify their types by setting
// missing receivers. To compute the method set of the interface, Complete must be called. // missing receivers. To compute the method set of the interface, Complete must be called.
// //
// Deprecated: Use NewInterface2 instead which allows any (even non-defined) interface types // Deprecated: Use NewInterfaceType instead which allows any (even non-defined) interface types
// to be embedded. This is necessary for interfaces that embed alias type names referring to // to be embedded. This is necessary for interfaces that embed alias type names referring to
// non-defined (literal) interface types. // non-defined (literal) interface types.
func NewInterface(methods []*Func, embeddeds []*Named) *Interface { func NewInterface(methods []*Func, embeddeds []*Named) *Interface {
...@@ -268,16 +268,16 @@ func NewInterface(methods []*Func, embeddeds []*Named) *Interface { ...@@ -268,16 +268,16 @@ func NewInterface(methods []*Func, embeddeds []*Named) *Interface {
for i, t := range embeddeds { for i, t := range embeddeds {
tnames[i] = t tnames[i] = t
} }
return NewInterface2(methods, tnames) return NewInterfaceType(methods, tnames)
} }
// NewInterface2 returns a new (incomplete) interface for the given methods and embedded types. // NewInterfaceType returns a new (incomplete) interface for the given methods and embedded types.
// Each embedded type must have an underlying type of interface type (this property is not // Each embedded type must have an underlying type of interface type (this property is not
// verified for defined types, which may be in the process of being set up and which don't // verified for defined types, which may be in the process of being set up and which don't
// have a valid underlying type yet). // have a valid underlying type yet).
// NewInterface2 takes ownership of the provided methods and may modify their types by setting // NewInterfaceType takes ownership of the provided methods and may modify their types by setting
// missing receivers. To compute the method set of the interface, Complete must be called. // missing receivers. To compute the method set of the interface, Complete must be called.
func NewInterface2(methods []*Func, embeddeds []Type) *Interface { func NewInterfaceType(methods []*Func, embeddeds []Type) *Interface {
typ := new(Interface) typ := new(Interface)
if len(methods) == 0 && len(embeddeds) == 0 { if len(methods) == 0 && len(embeddeds) == 0 {
...@@ -344,9 +344,9 @@ func (t *Interface) Method(i int) *Func { return t.allMethods[i] } ...@@ -344,9 +344,9 @@ func (t *Interface) Method(i int) *Func { return t.allMethods[i] }
func (t *Interface) Empty() bool { return len(t.allMethods) == 0 } func (t *Interface) Empty() bool { return len(t.allMethods) == 0 }
// Complete computes the interface's method set. It must be called by users of // Complete computes the interface's method set. It must be called by users of
// NewInterface after the interface's embedded types are fully defined and // NewInterfaceType and NewInterface after the interface's embedded types are
// before using the interface type in any way other than to form other types. // fully defined and before using the interface type in any way other than to
// Complete returns the receiver. // form other types. Complete returns the receiver.
func (t *Interface) Complete() *Interface { func (t *Interface) Complete() *Interface {
if t.allMethods != nil { if t.allMethods != nil {
return t return t
......
...@@ -162,19 +162,19 @@ func TestIncompleteInterfaces(t *testing.T) { ...@@ -162,19 +162,19 @@ func TestIncompleteInterfaces(t *testing.T) {
{NewInterface(nil, []*Named{newDefined(NewInterface([]*Func{m}, nil).Complete())}), "interface{T /* incomplete */}"}, {NewInterface(nil, []*Named{newDefined(NewInterface([]*Func{m}, nil).Complete())}), "interface{T /* incomplete */}"},
{NewInterface(nil, []*Named{newDefined(NewInterface([]*Func{m}, nil).Complete())}).Complete(), "interface{T}"}, {NewInterface(nil, []*Named{newDefined(NewInterface([]*Func{m}, nil).Complete())}).Complete(), "interface{T}"},
{NewInterface2(nil, nil), "interface{/* incomplete */}"}, {NewInterfaceType(nil, nil), "interface{/* incomplete */}"},
{NewInterface2(nil, nil).Complete(), "interface{}"}, {NewInterfaceType(nil, nil).Complete(), "interface{}"},
{NewInterface2([]*Func{}, nil), "interface{/* incomplete */}"}, {NewInterfaceType([]*Func{}, nil), "interface{/* incomplete */}"},
{NewInterface2([]*Func{}, nil).Complete(), "interface{}"}, {NewInterfaceType([]*Func{}, nil).Complete(), "interface{}"},
{NewInterface2(nil, []Type{}), "interface{/* incomplete */}"}, {NewInterfaceType(nil, []Type{}), "interface{/* incomplete */}"},
{NewInterface2(nil, []Type{}).Complete(), "interface{}"}, {NewInterfaceType(nil, []Type{}).Complete(), "interface{}"},
{NewInterface2([]*Func{m}, nil), "interface{m() /* incomplete */}"}, {NewInterfaceType([]*Func{m}, nil), "interface{m() /* incomplete */}"},
{NewInterface2([]*Func{m}, nil).Complete(), "interface{m()}"}, {NewInterfaceType([]*Func{m}, nil).Complete(), "interface{m()}"},
{NewInterface2(nil, []Type{new(Interface).Complete()}), "interface{interface{} /* incomplete */}"}, {NewInterfaceType(nil, []Type{new(Interface).Complete()}), "interface{interface{} /* incomplete */}"},
{NewInterface2(nil, []Type{new(Interface).Complete()}).Complete(), "interface{interface{}}"}, {NewInterfaceType(nil, []Type{new(Interface).Complete()}).Complete(), "interface{interface{}}"},
{NewInterface2(nil, []Type{NewInterface2([]*Func{m}, nil)}), "interface{interface{m() /* incomplete */} /* incomplete */}"}, {NewInterfaceType(nil, []Type{NewInterfaceType([]*Func{m}, nil)}), "interface{interface{m() /* incomplete */} /* incomplete */}"},
{NewInterface2(nil, []Type{NewInterface2([]*Func{m}, nil).Complete()}), "interface{interface{m()} /* incomplete */}"}, {NewInterfaceType(nil, []Type{NewInterfaceType([]*Func{m}, nil).Complete()}), "interface{interface{m()} /* incomplete */}"},
{NewInterface2(nil, []Type{NewInterface2([]*Func{m}, nil).Complete()}).Complete(), "interface{interface{m()}}"}, {NewInterfaceType(nil, []Type{NewInterfaceType([]*Func{m}, nil).Complete()}).Complete(), "interface{interface{m()}}"},
} { } {
got := test.typ.String() got := test.typ.String()
if got != test.want { if got != test.want {
......
...@@ -80,7 +80,7 @@ func defPredeclaredTypes() { ...@@ -80,7 +80,7 @@ func defPredeclaredTypes() {
res := NewVar(token.NoPos, nil, "", Typ[String]) res := NewVar(token.NoPos, nil, "", Typ[String])
sig := &Signature{results: NewTuple(res)} sig := &Signature{results: NewTuple(res)}
err := NewFunc(token.NoPos, nil, "Error", sig) err := NewFunc(token.NoPos, nil, "Error", sig)
typ := &Named{underlying: NewInterface2([]*Func{err}, nil).Complete()} typ := &Named{underlying: NewInterfaceType([]*Func{err}, nil).Complete()}
sig.recv = NewVar(token.NoPos, nil, "", typ) sig.recv = NewVar(token.NoPos, nil, "", typ)
def(NewTypeName(token.NoPos, nil, "error", typ)) def(NewTypeName(token.NoPos, nil, "error", typ))
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment