Skip to content

Commit 0d478d8

Browse files
griesemergopherbot
authored andcommitted
go/types, types2: add missing Unalias calls in type unifier
The unification code has "early exits" when the compared types are pointer-identical. Because of Alias nodes, we cannot simply compare x == y but we must compare Unalias(x) == Unalias(y). Still, in the common case there are no aliases, so as a minor optimization we write: x == y || Unalias(x) == Unalias(y) to test whether x and y are (pointer-) identical. Add the missing Unalias calls in the place where we forgot them. Fixes #67872. Change-Id: Ia26ffe7205b0417fc698287a4aeb1c900d30cc0d Reviewed-on: https://go-review.googlesource.com/c/go/+/591975 Reviewed-by: Robert Findley <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent beaf7f3 commit 0d478d8

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
344344
// that is a type parameter.
345345
assert(!isTypeParam(y))
346346
// x and y may be identical now
347-
if x == y {
347+
if x == y || Unalias(x) == Unalias(y) {
348348
return true
349349
}
350350
}

src/go/types/unify.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 = uint8
8+
type E uint8
9+
10+
func f[P ~A](P) {}
11+
12+
func g(e E) {
13+
f(e)
14+
}

0 commit comments

Comments
 (0)