From c23294d6b356590d5ebcaf153048111ee9b30465 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Sat, 5 Jun 2021 21:23:48 -0700 Subject: [PATCH] [dev.typeparams] cmd/compile/internal/types2: return Universe for ((*Package)(nil)).Scope() For #46594. Change-Id: I53776cbdc1b8f6da511abe2c6659a7313d7a163a Reviewed-on: https://go-review.googlesource.com/c/go/+/325469 Trust: Robert Griesemer Run-TryBot: Robert Griesemer TryBot-Result: Go Bot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/types2/package.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/types2/package.go b/src/cmd/compile/internal/types2/package.go index c5804a05adc..8044e7e6a76 100644 --- a/src/cmd/compile/internal/types2/package.go +++ b/src/cmd/compile/internal/types2/package.go @@ -48,7 +48,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.