aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-09-08 13:45:16 -0700
committerRobert Griesemer <gri@golang.org>2021-09-08 22:41:27 +0000
commit47f3e1e02c8737fd06397d957506f3724737cae0 (patch)
tree7957a1ef0a6783d657f8e7a1e75e3eee817670a7 /src
parentccc927b8f6550cb638e78fd63eebf422fc3c3d8a (diff)
downloadgo-47f3e1e02c8737fd06397d957506f3724737cae0.tar.xz
cmd/compile/internal/types2: move NewTypeParam off of Checker
This is a port of CL 347561. A comment was corrected both in types2 and go/types, and the compiler adjusted for the updated NewTypeParameter function. Change-Id: I4381f0dd8e43228e1d037c5d997d421b7838f905 Reviewed-on: https://go-review.googlesource.com/c/go/+/348574 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/importer/iimport.go2
-rw-r--r--src/cmd/compile/internal/noder/reader2.go2
-rw-r--r--src/cmd/compile/internal/types2/builtins.go2
-rw-r--r--src/cmd/compile/internal/types2/decl.go2
-rw-r--r--src/cmd/compile/internal/types2/typeparam.go10
-rw-r--r--src/go/types/typeparam.go2
6 files changed, 12 insertions, 8 deletions
diff --git a/src/cmd/compile/internal/importer/iimport.go b/src/cmd/compile/internal/importer/iimport.go
index 38cb8db235..646cad60d9 100644
--- a/src/cmd/compile/internal/importer/iimport.go
+++ b/src/cmd/compile/internal/importer/iimport.go
@@ -365,7 +365,7 @@ func (r *importReader) obj(name string) {
}
name0, sub := parseSubscript(name)
tn := types2.NewTypeName(pos, r.currPkg, name0, nil)
- t := (*types2.Checker)(nil).NewTypeParam(tn, nil)
+ t := types2.NewTypeParam(tn, nil)
if sub == 0 {
errorf("missing subscript")
}
diff --git a/src/cmd/compile/internal/noder/reader2.go b/src/cmd/compile/internal/noder/reader2.go
index 6c0d9c8c9d..a5e925b3db 100644
--- a/src/cmd/compile/internal/noder/reader2.go
+++ b/src/cmd/compile/internal/noder/reader2.go
@@ -483,7 +483,7 @@ func (r *reader2) typeParamNames() []*types2.TypeParam {
pkg, name := r.localIdent()
tname := types2.NewTypeName(pos, pkg, name, nil)
- r.dict.tparams[i] = r.p.check.NewTypeParam(tname, nil)
+ r.dict.tparams[i] = types2.NewTypeParam(tname, nil)
}
for i, bound := range r.dict.bounds {
diff --git a/src/cmd/compile/internal/types2/builtins.go b/src/cmd/compile/internal/types2/builtins.go
index e3844d5163..3b8d85859a 100644
--- a/src/cmd/compile/internal/types2/builtins.go
+++ b/src/cmd/compile/internal/types2/builtins.go
@@ -826,7 +826,7 @@ func (check *Checker) applyTypeFunc(f func(Type) Type, x Type) Type {
// type param is placed in the current package so export/import
// works as expected.
tpar := NewTypeName(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
return ptyp
diff --git a/src/cmd/compile/internal/types2/decl.go b/src/cmd/compile/internal/types2/decl.go
index 1d46b004b6..5be4a9f804 100644
--- a/src/cmd/compile/internal/types2/decl.go
+++ b/src/cmd/compile/internal/types2/decl.go
@@ -648,7 +648,7 @@ func (check *Checker) declareTypeParam(name *syntax.Name) *TypeParam {
// constraints to make sure we don't rely on them if they
// are not properly set yet.
tname := NewTypeName(name.Pos(), check.pkg, name.Value, nil)
- tpar := check.NewTypeParam(tname, Typ[Invalid]) // assigns type to tname as a side-effect
+ tpar := check.newTypeParam(tname, Typ[Invalid]) // assigns type to tname as a side-effect
check.declare(check.scope, name, tname, check.scope.pos) // TODO(gri) check scope position
return tpar
}
diff --git a/src/cmd/compile/internal/types2/typeparam.go b/src/cmd/compile/internal/types2/typeparam.go
index 445337fee8..e7181281af 100644
--- a/src/cmd/compile/internal/types2/typeparam.go
+++ b/src/cmd/compile/internal/types2/typeparam.go
@@ -32,15 +32,19 @@ func (t *TypeParam) Obj() *TypeName { return t.obj }
// or Signature type by calling SetTParams. Setting a type parameter on more
// than one type will result in a panic.
//
-// The bound argument can be nil, and set later via SetBound.
-func (check *Checker) NewTypeParam(obj *TypeName, bound Type) *TypeParam {
+// The constraint argument can be nil, and set later via SetConstraint.
+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.
id := nextID()
if check != nil {
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 {
obj.typ = typ
}
diff --git a/src/go/types/typeparam.go b/src/go/types/typeparam.go
index a0f2a3acd0..150ad079a8 100644
--- a/src/go/types/typeparam.go
+++ b/src/go/types/typeparam.go
@@ -32,7 +32,7 @@ type TypeParam struct {
// or Signature type by calling SetTypeParams. Setting a type parameter on more
// than one type will result in a panic.
//
-// The bound argument can be nil, and set later via SetConstraint.
+// The constraint argument can be nil, and set later via SetConstraint.
func NewTypeParam(obj *TypeName, constraint Type) *TypeParam {
return (*Checker)(nil).newTypeParam(obj, constraint)
}