]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: return Universe for (*Package)(nil).Scope()
authorMatthew Dempsky <mdempsky@google.com>
Tue, 15 Feb 2022 01:20:48 +0000 (17:20 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 16 Mar 2022 00:34:27 +0000 (00:34 +0000)
Port of go.dev/cl/325469.

Fixes #46594.

Change-Id: I4bcdafecaa86885360599c204678871646bb221b
Reviewed-on: https://go-review.googlesource.com/c/go/+/385997
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/go/types/package.go

index 7b89def1b5d5137c5572131cf336cb12f97e3257..26385dc39b95fbe41b382f1477cb8f00af5f807c 100644 (file)
@@ -39,7 +39,13 @@ func (pkg *Package) SetName(name string) { pkg.name = name }
 // Scope returns the (complete or incomplete) package scope
 // holding the objects declared at package level (TypeNames,
 // Consts, Vars, and Funcs).
-func (pkg *Package) Scope() *Scope { return pkg.scope }
+// For a nil pkg receiver, Scope returns the Universe scope.
+func (pkg *Package) Scope() *Scope {
+       if pkg != nil {
+               return pkg.scope
+       }
+       return Universe
+}
 
 // A package is complete if its scope contains (at least) all
 // exported objects; otherwise it is incomplete.