mirror of
https://github.com/golang/go.git
synced 2025-05-29 03:11:26 +00:00
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:
parent
10d3b13551
commit
ccd41cc05e
@ -389,6 +389,8 @@ func (obj *Func) FullName() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Scope returns the scope of the function's body block.
|
// 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 }
|
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.
|
// hasPtrRecv reports whether the receiver is of the form *T for the given method obj.
|
||||||
|
@ -18,7 +18,7 @@ type Signature struct {
|
|||||||
// We then unpack the *Signature and use the scope for the literal body.
|
// We then unpack the *Signature and use the scope for the literal body.
|
||||||
rparams *TypeParamList // receiver type parameters from left to right, or nil
|
rparams *TypeParamList // receiver type parameters from left to right, or nil
|
||||||
tparams *TypeParamList // 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
|
recv *Var // nil if not a method
|
||||||
params *Tuple // (incoming) parameters from left to right; or nil
|
params *Tuple // (incoming) parameters from left to right; or nil
|
||||||
results *Tuple // (outgoing) results from left to right; or nil
|
results *Tuple // (outgoing) results from left to right; or nil
|
||||||
|
@ -115,8 +115,8 @@ func (subst *subster) typ(typ Type) Type {
|
|||||||
return &Signature{
|
return &Signature{
|
||||||
rparams: t.rparams,
|
rparams: t.rparams,
|
||||||
// TODO(gri) why can't we nil out tparams here, rather than in instantiate?
|
// TODO(gri) why can't we nil out tparams here, rather than in instantiate?
|
||||||
tparams: t.tparams,
|
tparams: t.tparams,
|
||||||
scope: t.scope,
|
// instantiated signatures have a nil scope
|
||||||
recv: recv,
|
recv: recv,
|
||||||
params: params,
|
params: params,
|
||||||
results: results,
|
results: results,
|
||||||
|
@ -343,6 +343,8 @@ func (obj *Func) FullName() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Scope returns the scope of the function's body block.
|
// 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 }
|
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.
|
// hasPtrRecv reports whether the receiver is of the form *T for the given method obj.
|
||||||
|
@ -21,7 +21,7 @@ type Signature struct {
|
|||||||
// We then unpack the *Signature and use the scope for the literal body.
|
// We then unpack the *Signature and use the scope for the literal body.
|
||||||
rparams *TypeParamList // receiver type parameters from left to right, or nil
|
rparams *TypeParamList // receiver type parameters from left to right, or nil
|
||||||
tparams *TypeParamList // 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
|
recv *Var // nil if not a method
|
||||||
params *Tuple // (incoming) parameters from left to right; or nil
|
params *Tuple // (incoming) parameters from left to right; or nil
|
||||||
results *Tuple // (outgoing) results from left to right; or nil
|
results *Tuple // (outgoing) results from left to right; or nil
|
||||||
|
@ -115,8 +115,8 @@ func (subst *subster) typ(typ Type) Type {
|
|||||||
return &Signature{
|
return &Signature{
|
||||||
rparams: t.rparams,
|
rparams: t.rparams,
|
||||||
// TODO(rFindley) why can't we nil out tparams here, rather than in instantiate?
|
// TODO(rFindley) why can't we nil out tparams here, rather than in instantiate?
|
||||||
tparams: t.tparams,
|
tparams: t.tparams,
|
||||||
scope: t.scope,
|
// instantiated signatures have a nil scope
|
||||||
recv: recv,
|
recv: recv,
|
||||||
params: params,
|
params: params,
|
||||||
results: results,
|
results: results,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user