Skip to content

Commit 1a90dcd

Browse files
committed
go/types, types2: unalias tilde terms in underIs
Unalias the ~T terms during underIs. Before, if T was an alias of U, it may pass T to the iteration function. The iterator function expects an underlying type, under(U), to be passed. This caused several bugs where underIs is used without eventually taking the underlying type. Updates #68935 Fixes #68903 Change-Id: Ie8691d8dddaea00e1dcba94d17c0f1b021fc49a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/606075 Reviewed-by: Robert Griesemer <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 6fb6ace commit 1a90dcd

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ func (s *_TypeSet) underIs(f func(Type) bool) bool {
131131
}
132132
for _, t := range s.terms {
133133
assert(t.typ != nil)
134-
// x == under(x) for ~x terms
135-
u := t.typ
134+
// Unalias(x) == under(x) for ~x terms
135+
u := Unalias(t.typ)
136136
if !t.tilde {
137137
u = under(u)
138138
}

src/go/types/typeset.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
type A = [4]int
8+
type B = map[string]interface{}
9+
10+
func _[T ~A](x T) {
11+
_ = len(x)
12+
}
13+
14+
func _[U ~A](x U) {
15+
_ = cap(x)
16+
}
17+
18+
func _[V ~A]() {
19+
_ = V{}
20+
}
21+
22+
func _[W ~B](a interface{}) {
23+
_ = a.(W)["key"]
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
type A = struct {
8+
F string
9+
G int
10+
}
11+
12+
func Make[T ~A]() T {
13+
return T{
14+
F: "blah",
15+
G: 1234,
16+
}
17+
}
18+
19+
type N struct {
20+
F string
21+
G int
22+
}
23+
24+
func _() {
25+
_ = Make[N]()
26+
}

0 commit comments

Comments
 (0)