aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder
diff options
context:
space:
mode:
authorRob Findley <rfindley@google.com>2024-04-19 14:51:18 +0000
committerRobert Findley <rfindley@google.com>2024-05-07 20:08:23 +0000
commit4ed358b57efdad9ed710be7f4fc51495a7620ce2 (patch)
treec7b0c3c3dfd03eaf7ad45fe26377fb442afb35c6 /src/cmd/compile/internal/noder
parent9c5269c2530162fd898e81c3eb12b98cef01d6a5 (diff)
downloadgo-4ed358b57efdad9ed710be7f4fc51495a7620ce2.tar.xz
go/types, types: represent any using Alias
When GODEBUG=gotypesalias=1 is set, use an actual Alias type to represent any, rather than a legacy alias representation. This makes any consistent with other interface aliases, and will eventually make obsolete the various workarounds for formatting any as 'any' rather than 'interface{}'. Since any is a global in the Universe scope, we must hijack Scope.Lookup to select the correct representation. Of course, this also means that we can't support type checking concurrently while mutating gotypesalias (or, in the case of types2, Config.EnableAlias). Some care is taken to ensure that the type checker panics in the event of this type of misuse. For now, we must still support the legacy representation of any, and the existing workarounds that look for a distinguished any pointer. This is done by ensuring that both representations have the same underlying pointer, and by updating workarounds to consider Underlying. Fixes golang/go#66921 Change-Id: I81db7e8e15317b7a6ed3b406545db15a2fc42f57 Reviewed-on: https://go-review.googlesource.com/c/go/+/580355 Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd/compile/internal/noder')
-rw-r--r--src/cmd/compile/internal/noder/writer.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/noder/writer.go b/src/cmd/compile/internal/noder/writer.go
index 785176b3b5..453b08dbf9 100644
--- a/src/cmd/compile/internal/noder/writer.go
+++ b/src/cmd/compile/internal/noder/writer.go
@@ -569,7 +569,10 @@ func (pw *pkgWriter) typIdx(typ types2.Type, dict *writerDict) typeInfo {
case *types2.Interface:
// Handle "any" as reference to its TypeName.
- if typ == anyTypeName.Type() {
+ // The underlying "any" interface is canonical, so this logic handles both
+ // GODEBUG=gotypesalias=1 (when any is represented as a types2.Alias), and
+ // gotypesalias=0.
+ if types2.Unalias(typ) == types2.Unalias(anyTypeName.Type()) {
w.Code(pkgbits.TypeNamed)
w.obj(anyTypeName, nil)
break