1
0
mirror of https://github.com/golang/go synced 2024-11-22 14:54:46 -07:00

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/120875
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Robert Griesemer 2018-06-25 16:21:59 -07:00
parent 8997ec1c4e
commit cd016af6b6
7 changed files with 26 additions and 26 deletions

View File

@ -437,7 +437,7 @@ pkg debug/pe, const IMAGE_FILE_MACHINE_ARM64 = 43620
pkg debug/pe, const IMAGE_FILE_MACHINE_ARM64 ideal-int
pkg go/ast, type CompositeLit struct, Incomplete bool
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 (*Var) Embedded() bool
pkg net, method (*ListenConfig) Listen(context.Context, string, string) (Listener, error)

View File

@ -600,7 +600,7 @@ func (p *parser) parseInterfaceType(pkg *types.Package) types.Type {
}
p.expect('}')
return types.NewInterface2(methods, embeddeds)
return types.NewInterfaceType(methods, embeddeds)
}
// PointerType = "*" ("any" | Type) .

View File

@ -536,7 +536,7 @@ func (p *importer) typ(parent *types.Package, tname *types.Named) types.Type {
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)
if p.trackAllTypes {
p.typList[n] = t

View File

@ -535,7 +535,7 @@ func (r *importReader) doType(base *types.Named) types.Type {
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)
return typ
}

View File

@ -260,7 +260,7 @@ var markComplete = make([]*Func, 0)
// 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.
//
// 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
// non-defined (literal) interface types.
func NewInterface(methods []*Func, embeddeds []*Named) *Interface {
@ -268,16 +268,16 @@ func NewInterface(methods []*Func, embeddeds []*Named) *Interface {
for i, t := range embeddeds {
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
// verified for defined types, which may be in the process of being set up and which don't
// 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.
func NewInterface2(methods []*Func, embeddeds []Type) *Interface {
func NewInterfaceType(methods []*Func, embeddeds []Type) *Interface {
typ := new(Interface)
if len(methods) == 0 && len(embeddeds) == 0 {
@ -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 }
// 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
// before using the interface type in any way other than to form other types.
// Complete returns the receiver.
// NewInterfaceType and NewInterface after the interface's embedded types are
// fully defined and before using the interface type in any way other than to
// form other types. Complete returns the receiver.
func (t *Interface) Complete() *Interface {
if t.allMethods != nil {
return t

View File

@ -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())}).Complete(), "interface{T}"},
{NewInterface2(nil, nil), "interface{/* incomplete */}"},
{NewInterface2(nil, nil).Complete(), "interface{}"},
{NewInterface2([]*Func{}, nil), "interface{/* incomplete */}"},
{NewInterface2([]*Func{}, nil).Complete(), "interface{}"},
{NewInterface2(nil, []Type{}), "interface{/* incomplete */}"},
{NewInterface2(nil, []Type{}).Complete(), "interface{}"},
{NewInterface2([]*Func{m}, nil), "interface{m() /* incomplete */}"},
{NewInterface2([]*Func{m}, nil).Complete(), "interface{m()}"},
{NewInterface2(nil, []Type{new(Interface).Complete()}), "interface{interface{} /* incomplete */}"},
{NewInterface2(nil, []Type{new(Interface).Complete()}).Complete(), "interface{interface{}}"},
{NewInterface2(nil, []Type{NewInterface2([]*Func{m}, nil)}), "interface{interface{m() /* incomplete */} /* incomplete */}"},
{NewInterface2(nil, []Type{NewInterface2([]*Func{m}, nil).Complete()}), "interface{interface{m()} /* incomplete */}"},
{NewInterface2(nil, []Type{NewInterface2([]*Func{m}, nil).Complete()}).Complete(), "interface{interface{m()}}"},
{NewInterfaceType(nil, nil), "interface{/* incomplete */}"},
{NewInterfaceType(nil, nil).Complete(), "interface{}"},
{NewInterfaceType([]*Func{}, nil), "interface{/* incomplete */}"},
{NewInterfaceType([]*Func{}, nil).Complete(), "interface{}"},
{NewInterfaceType(nil, []Type{}), "interface{/* incomplete */}"},
{NewInterfaceType(nil, []Type{}).Complete(), "interface{}"},
{NewInterfaceType([]*Func{m}, nil), "interface{m() /* incomplete */}"},
{NewInterfaceType([]*Func{m}, nil).Complete(), "interface{m()}"},
{NewInterfaceType(nil, []Type{new(Interface).Complete()}), "interface{interface{} /* incomplete */}"},
{NewInterfaceType(nil, []Type{new(Interface).Complete()}).Complete(), "interface{interface{}}"},
{NewInterfaceType(nil, []Type{NewInterfaceType([]*Func{m}, nil)}), "interface{interface{m() /* incomplete */} /* incomplete */}"},
{NewInterfaceType(nil, []Type{NewInterfaceType([]*Func{m}, nil).Complete()}), "interface{interface{m()} /* incomplete */}"},
{NewInterfaceType(nil, []Type{NewInterfaceType([]*Func{m}, nil).Complete()}).Complete(), "interface{interface{m()}}"},
} {
got := test.typ.String()
if got != test.want {

View File

@ -80,7 +80,7 @@ func defPredeclaredTypes() {
res := NewVar(token.NoPos, nil, "", Typ[String])
sig := &Signature{results: NewTuple(res)}
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)
def(NewTypeName(token.NoPos, nil, "error", typ))
}