Skip to content

Commit 1b87338

Browse files
cuonglmSirherobrine23
authored andcommitted
cmd/compile: fix ICE with recursive alias type parameter
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 golang#66873. Updates golang#73309. Change-Id: I2559bed37e21615854333fb1057d7349406e6a1b Reviewed-on: https://go-review.googlesource.com/c/go/+/668175 Reviewed-by: David Chase <[email protected]> Reviewed-by: Keith Randall <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 49736e0 commit 1b87338

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

src/cmd/compile/internal/noder/reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ func (pr *pkgReader) objIdxMayFail(idx index, implicits, explicits []*types.Type
762762
if hack {
763763
if sym.Def != nil {
764764
name = sym.Def.(*ir.Name)
765-
assert(name.Type() == typ)
765+
assert(types.IdenticalStrict(name.Type(), typ))
766766
return name, nil
767767
}
768768
sym.Def = name

src/cmd/compile/internal/types2/stdlib_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ func TestStdFixed(t *testing.T) {
332332
"issue49814.go", // go/types does not have constraints on array size
333333
"issue56103.go", // anonymous interface cycles; will be a type checker error in 1.22
334334
"issue52697.go", // types2 does not have constraints on stack size
335+
"issue73309.go", // this test requires GODEBUG=gotypesalias=1
335336

336337
// These tests requires runtime/cgo.Incomplete, which is only available on some platforms.
337338
// However, types2 does not know about build constraints.

src/go/types/stdlib_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ func TestStdFixed(t *testing.T) {
334334
"issue49814.go", // go/types does not have constraints on array size
335335
"issue56103.go", // anonymous interface cycles; will be a type checker error in 1.22
336336
"issue52697.go", // go/types does not have constraints on stack size
337+
"issue73309.go", // this test requires GODEBUG=gotypesalias=1
337338

338339
// These tests requires runtime/cgo.Incomplete, which is only available on some platforms.
339340
// However, go/types does not know about build constraints.

test/fixedbugs/issue73309.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// compile
2+
3+
// Copyright 2025 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
type B[T any] struct {
10+
a A[T]
11+
}
12+
13+
type A[T any] = func(B[T]) bool
14+
15+
func main() {
16+
var s A[int]
17+
println(s)
18+
}

0 commit comments

Comments
 (0)