Skip to content

Commit 38c2e08

Browse files
committed
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 <[email protected]> Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent cb9ccd4 commit 38c2e08

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/go/internal/gcimporter/iimport.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func (r *importReader) obj(name string) {
355355
}
356356
name0, sub := parseSubscript(name)
357357
tn := types.NewTypeName(pos, r.currPkg, name0, nil)
358-
t := (*types.Checker)(nil).NewTypeParam(tn, nil)
358+
t := types.NewTypeParam(tn, nil)
359359
if sub == 0 {
360360
errorf("missing subscript")
361361
}

src/go/types/builtins.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ func (check *Checker) applyTypeFunc(f func(Type) Type, x Type) Type {
830830
// type param is placed in the current package so export/import
831831
// works as expected.
832832
tpar := NewTypeName(token.NoPos, check.pkg, "<type parameter>", nil)
833-
ptyp := check.NewTypeParam(tpar, NewInterfaceType(nil, []Type{NewUnion(terms)})) // assigns type to tpar as a side-effect
833+
ptyp := check.newTypeParam(tpar, NewInterfaceType(nil, []Type{NewUnion(terms)})) // assigns type to tpar as a side-effect
834834
ptyp.index = tp.index
835835

836836
return ptyp

src/go/types/decl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ func (check *Checker) collectTypeParams(list *ast.FieldList) *TParamList {
677677
func (check *Checker) declareTypeParams(tparams []*TypeParam, names []*ast.Ident) []*TypeParam {
678678
for _, name := range names {
679679
tname := NewTypeName(name.Pos(), check.pkg, name.Name, nil)
680-
tpar := check.NewTypeParam(tname, &emptyInterface) // assigns type to tpar as a side-effect
680+
tpar := check.newTypeParam(tname, &emptyInterface) // assigns type to tpar as a side-effect
681681
check.declare(check.scope, name, tname, check.scope.pos) // TODO(gri) check scope position
682682
tparams = append(tparams, tpar)
683683
}

src/go/types/typeparam.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ type TypeParam struct {
3232
// or Signature type by calling SetTParams. Setting a type parameter on more
3333
// than one type will result in a panic.
3434
//
35-
// The bound argument can be nil, and set later via SetBound.
36-
func (check *Checker) NewTypeParam(obj *TypeName, bound Type) *TypeParam {
35+
// The bound argument can be nil, and set later via SetConstraint.
36+
func NewTypeParam(obj *TypeName, constraint Type) *TypeParam {
37+
return (*Checker)(nil).newTypeParam(obj, constraint)
38+
}
39+
40+
func (check *Checker) newTypeParam(obj *TypeName, constraint Type) *TypeParam {
3741
// Always increment lastID, even if it is not used.
3842
id := nextID()
3943
if check != nil {
4044
check.nextID++
4145
id = check.nextID
4246
}
43-
typ := &TypeParam{check: check, id: id, obj: obj, index: -1, bound: bound}
47+
typ := &TypeParam{check: check, id: id, obj: obj, index: -1, bound: constraint}
4448
if obj.typ == nil {
4549
obj.typ = typ
4650
}

0 commit comments

Comments
 (0)