Skip to content

Commit ccd41cc

Browse files
committed
go/types, types2: document nil scope for imported and instantiated Func objects
Also, don't set the scope anymore when instantiating (substituting) a signature. Per discussion with rfindley. Change-Id: I560d4571c7ff14b0df3e15fece634cb5f9f94a99 Reviewed-on: https://go-review.googlesource.com/c/go/+/363435 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
1 parent 10d3b13 commit ccd41cc

File tree

6 files changed

+10
-6
lines changed

6 files changed

+10
-6
lines changed

src/cmd/compile/internal/types2/object.go

+2
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ func (obj *Func) FullName() string {
389389
}
390390

391391
// Scope returns the scope of the function's body block.
392+
// The result is nil for imported or instantiated functions and methods
393+
// (but there is also no mechanism to get to an instantiated function).
392394
func (obj *Func) Scope() *Scope { return obj.typ.(*Signature).scope }
393395

394396
// hasPtrRecv reports whether the receiver is of the form *T for the given method obj.

src/cmd/compile/internal/types2/signature.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type Signature struct {
1818
// We then unpack the *Signature and use the scope for the literal body.
1919
rparams *TypeParamList // receiver type parameters from left to right, or nil
2020
tparams *TypeParamList // type parameters from left to right, or nil
21-
scope *Scope // function scope, present for package-local signatures
21+
scope *Scope // function scope for package-local and non-instantiated signatures; nil otherwise
2222
recv *Var // nil if not a method
2323
params *Tuple // (incoming) parameters from left to right; or nil
2424
results *Tuple // (outgoing) results from left to right; or nil

src/cmd/compile/internal/types2/subst.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ func (subst *subster) typ(typ Type) Type {
115115
return &Signature{
116116
rparams: t.rparams,
117117
// TODO(gri) why can't we nil out tparams here, rather than in instantiate?
118-
tparams: t.tparams,
119-
scope: t.scope,
118+
tparams: t.tparams,
119+
// instantiated signatures have a nil scope
120120
recv: recv,
121121
params: params,
122122
results: results,

src/go/types/object.go

+2
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ func (obj *Func) FullName() string {
343343
}
344344

345345
// Scope returns the scope of the function's body block.
346+
// The result is nil for imported or instantiated functions and methods
347+
// (but there is also no mechanism to get to an instantiated function).
346348
func (obj *Func) Scope() *Scope { return obj.typ.(*Signature).scope }
347349

348350
// hasPtrRecv reports whether the receiver is of the form *T for the given method obj.

src/go/types/signature.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Signature struct {
2121
// We then unpack the *Signature and use the scope for the literal body.
2222
rparams *TypeParamList // receiver type parameters from left to right, or nil
2323
tparams *TypeParamList // type parameters from left to right, or nil
24-
scope *Scope // function scope, present for package-local signatures
24+
scope *Scope // function scope for package-local and non-instantiated signatures; nil otherwise
2525
recv *Var // nil if not a method
2626
params *Tuple // (incoming) parameters from left to right; or nil
2727
results *Tuple // (outgoing) results from left to right; or nil

src/go/types/subst.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ func (subst *subster) typ(typ Type) Type {
115115
return &Signature{
116116
rparams: t.rparams,
117117
// TODO(rFindley) why can't we nil out tparams here, rather than in instantiate?
118-
tparams: t.tparams,
119-
scope: t.scope,
118+
tparams: t.tparams,
119+
// instantiated signatures have a nil scope
120120
recv: recv,
121121
params: params,
122122
results: results,

0 commit comments

Comments
 (0)