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>
This commit is contained in:
Robert Griesemer 2021-11-11 11:57:43 -08:00
parent 10d3b13551
commit ccd41cc05e
6 changed files with 10 additions and 6 deletions

View File

@ -389,6 +389,8 @@ func (obj *Func) FullName() string {
}
// Scope returns the scope of the function's body block.
// The result is nil for imported or instantiated functions and methods
// (but there is also no mechanism to get to an instantiated function).
func (obj *Func) Scope() *Scope { return obj.typ.(*Signature).scope }
// hasPtrRecv reports whether the receiver is of the form *T for the given method obj.

View File

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

View File

@ -115,8 +115,8 @@ func (subst *subster) typ(typ Type) Type {
return &Signature{
rparams: t.rparams,
// TODO(gri) why can't we nil out tparams here, rather than in instantiate?
tparams: t.tparams,
scope: t.scope,
tparams: t.tparams,
// instantiated signatures have a nil scope
recv: recv,
params: params,
results: results,

View File

@ -343,6 +343,8 @@ func (obj *Func) FullName() string {
}
// Scope returns the scope of the function's body block.
// The result is nil for imported or instantiated functions and methods
// (but there is also no mechanism to get to an instantiated function).
func (obj *Func) Scope() *Scope { return obj.typ.(*Signature).scope }
// hasPtrRecv reports whether the receiver is of the form *T for the given method obj.

View File

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

View File

@ -115,8 +115,8 @@ func (subst *subster) typ(typ Type) Type {
return &Signature{
rparams: t.rparams,
// TODO(rFindley) why can't we nil out tparams here, rather than in instantiate?
tparams: t.tparams,
scope: t.scope,
tparams: t.tparams,
// instantiated signatures have a nil scope
recv: recv,
params: params,
results: results,