]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix ICE with recursive alias type parameter
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 25 Apr 2025 12:13:52 +0000 (19:13 +0700)
committerGopher Robot <gobot@golang.org>
Thu, 22 May 2025 18:23:35 +0000 (11:23 -0700)
CL 585399 fixed an initialization loop during IR contruction that
involving alias type, by avoiding publishing alias declarations until
the RHS type expression has been constructed.

There's an assertion to ensure that the alias's type must be the same
during the initialization. However, that assertion is too strict, since
we may construct different instances of the same type, if the type is an
instantination of generic type.

To fix this, we could use types.IdenticalStrict to ensure that these
types matching exactly.

Updates #66873.
Updates #73309.

Change-Id: I2559bed37e21615854333fb1057d7349406e6a1b
Reviewed-on: https://go-review.googlesource.com/c/go/+/668175
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
src/cmd/compile/internal/noder/reader.go
src/cmd/compile/internal/types2/stdlib_test.go
src/go/types/stdlib_test.go
test/fixedbugs/issue73309.go [new file with mode: 0644]

index 05052651c69c61b5608a7e09396d386541bb571c..95054a4f8b6e52aa7b9cb154823f054890889839 100644 (file)
@@ -762,7 +762,7 @@ func (pr *pkgReader) objIdxMayFail(idx index, implicits, explicits []*types.Type
                if hack {
                        if sym.Def != nil {
                                name = sym.Def.(*ir.Name)
-                               assert(name.Type() == typ)
+                               assert(types.IdenticalStrict(name.Type(), typ))
                                return name, nil
                        }
                        sym.Def = name
index 6966bb94b00f26feb450aaf0334d88eb2ccabb61..4de698baaf823692808d9ea5db51409ce7af8bf5 100644 (file)
@@ -332,6 +332,7 @@ func TestStdFixed(t *testing.T) {
                "issue49814.go",  // go/types does not have constraints on array size
                "issue56103.go",  // anonymous interface cycles; will be a type checker error in 1.22
                "issue52697.go",  // types2 does not have constraints on stack size
+               "issue73309.go",  // this test requires GODEBUG=gotypesalias=1
 
                // These tests requires runtime/cgo.Incomplete, which is only available on some platforms.
                // However, types2 does not know about build constraints.
index ec76f8ee17214059958ad19eb53cde7e16941344..633d7be84da7338d81ce861a7bc9f304c9521ec2 100644 (file)
@@ -334,6 +334,7 @@ func TestStdFixed(t *testing.T) {
                "issue49814.go",  // go/types does not have constraints on array size
                "issue56103.go",  // anonymous interface cycles; will be a type checker error in 1.22
                "issue52697.go",  // go/types does not have constraints on stack size
+               "issue73309.go",  // this test requires GODEBUG=gotypesalias=1
 
                // These tests requires runtime/cgo.Incomplete, which is only available on some platforms.
                // However, go/types does not know about build constraints.
diff --git a/test/fixedbugs/issue73309.go b/test/fixedbugs/issue73309.go
new file mode 100644 (file)
index 0000000..5e96e65
--- /dev/null
@@ -0,0 +1,18 @@
+// compile
+
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+type B[T any] struct {
+       a A[T]
+}
+
+type A[T any] = func(B[T]) bool
+
+func main() {
+       var s A[int]
+       println(s)
+}