]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: document nil scope for imported and instantiated Func objects
authorRobert Griesemer <gri@golang.org>
Thu, 11 Nov 2021 19:57:43 +0000 (11:57 -0800)
committerRobert Griesemer <gri@golang.org>
Thu, 11 Nov 2021 20:45:40 +0000 (20:45 +0000)
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>
src/cmd/compile/internal/types2/object.go
src/cmd/compile/internal/types2/signature.go
src/cmd/compile/internal/types2/subst.go
src/go/types/object.go
src/go/types/signature.go
src/go/types/subst.go

index d86c166c7276307f207866d49804d3ae72348eec..da3e1a2abcecaf8f87ef37c3d2048754d1038ff9 100644 (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.
index 45414355879b1e8c16b48b2cca40a70db9efc165..b0b8ad49d981239a836bd011972fe5467704ffb4 100644 (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
index a4e46b209745759ca8a88d7df740ac9d51e2113f..f46e895b128e36bcf35559ba379886b7b3fb2b02 100644 (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,
index e7a4425643d971c0a667d27fd913bcbbcb940720..9309a529c4a1b2e2a19020343ba97f8e8e6ceb07 100644 (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.
index ad69c95d1288fd88ab104fc369bd9de827da69c8..3e0a046afa5e505263881d06fa29de2e86ccbc74 100644 (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
index 1fac82fe8a79e6b1af7e97dbea21f8b83cc4344d..a05195150f6b7566bb5922ea0b24ebea6b0bcd76 100644 (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,