mirror of https://github.com/golang/go.git
go/types: move NewTypeParam off of Checker
This aligns with the API proposal. Change-Id: I9967a317196392ffa5ddbe5391d7aba5f6e7bad2 Reviewed-on: https://go-review.googlesource.com/c/go/+/347561 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
cb9ccd494b
commit
38c2e08cbd
|
|
@ -355,7 +355,7 @@ func (r *importReader) obj(name string) {
|
||||||
}
|
}
|
||||||
name0, sub := parseSubscript(name)
|
name0, sub := parseSubscript(name)
|
||||||
tn := types.NewTypeName(pos, r.currPkg, name0, nil)
|
tn := types.NewTypeName(pos, r.currPkg, name0, nil)
|
||||||
t := (*types.Checker)(nil).NewTypeParam(tn, nil)
|
t := types.NewTypeParam(tn, nil)
|
||||||
if sub == 0 {
|
if sub == 0 {
|
||||||
errorf("missing subscript")
|
errorf("missing subscript")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -830,7 +830,7 @@ func (check *Checker) applyTypeFunc(f func(Type) Type, x Type) Type {
|
||||||
// type param is placed in the current package so export/import
|
// type param is placed in the current package so export/import
|
||||||
// works as expected.
|
// works as expected.
|
||||||
tpar := NewTypeName(token.NoPos, check.pkg, "<type parameter>", nil)
|
tpar := NewTypeName(token.NoPos, check.pkg, "<type parameter>", nil)
|
||||||
ptyp := check.NewTypeParam(tpar, NewInterfaceType(nil, []Type{NewUnion(terms)})) // assigns type to tpar as a side-effect
|
ptyp := check.newTypeParam(tpar, NewInterfaceType(nil, []Type{NewUnion(terms)})) // assigns type to tpar as a side-effect
|
||||||
ptyp.index = tp.index
|
ptyp.index = tp.index
|
||||||
|
|
||||||
return ptyp
|
return ptyp
|
||||||
|
|
|
||||||
|
|
@ -677,7 +677,7 @@ func (check *Checker) collectTypeParams(list *ast.FieldList) *TParamList {
|
||||||
func (check *Checker) declareTypeParams(tparams []*TypeParam, names []*ast.Ident) []*TypeParam {
|
func (check *Checker) declareTypeParams(tparams []*TypeParam, names []*ast.Ident) []*TypeParam {
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
tname := NewTypeName(name.Pos(), check.pkg, name.Name, nil)
|
tname := NewTypeName(name.Pos(), check.pkg, name.Name, nil)
|
||||||
tpar := check.NewTypeParam(tname, &emptyInterface) // assigns type to tpar as a side-effect
|
tpar := check.newTypeParam(tname, &emptyInterface) // assigns type to tpar as a side-effect
|
||||||
check.declare(check.scope, name, tname, check.scope.pos) // TODO(gri) check scope position
|
check.declare(check.scope, name, tname, check.scope.pos) // TODO(gri) check scope position
|
||||||
tparams = append(tparams, tpar)
|
tparams = append(tparams, tpar)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,15 +32,19 @@ type TypeParam struct {
|
||||||
// or Signature type by calling SetTParams. Setting a type parameter on more
|
// or Signature type by calling SetTParams. Setting a type parameter on more
|
||||||
// than one type will result in a panic.
|
// than one type will result in a panic.
|
||||||
//
|
//
|
||||||
// The bound argument can be nil, and set later via SetBound.
|
// The bound argument can be nil, and set later via SetConstraint.
|
||||||
func (check *Checker) NewTypeParam(obj *TypeName, bound Type) *TypeParam {
|
func NewTypeParam(obj *TypeName, constraint Type) *TypeParam {
|
||||||
|
return (*Checker)(nil).newTypeParam(obj, constraint)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (check *Checker) newTypeParam(obj *TypeName, constraint Type) *TypeParam {
|
||||||
// Always increment lastID, even if it is not used.
|
// Always increment lastID, even if it is not used.
|
||||||
id := nextID()
|
id := nextID()
|
||||||
if check != nil {
|
if check != nil {
|
||||||
check.nextID++
|
check.nextID++
|
||||||
id = check.nextID
|
id = check.nextID
|
||||||
}
|
}
|
||||||
typ := &TypeParam{check: check, id: id, obj: obj, index: -1, bound: bound}
|
typ := &TypeParam{check: check, id: id, obj: obj, index: -1, bound: constraint}
|
||||||
if obj.typ == nil {
|
if obj.typ == nil {
|
||||||
obj.typ = typ
|
obj.typ = typ
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue