Skip to content

Commit

Permalink
go/types, types2: add missing Unalias calls in type unifier
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
griesemer authored and gopherbot committed Jun 11, 2024
1 parent beaf7f3 commit 0d478d8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/types2/unify.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
// that is a type parameter.
assert(!isTypeParam(y))
// x and y may be identical now
if x == y {
if x == y || Unalias(x) == Unalias(y) {
return true
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/unify.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/internal/types/testdata/fixedbugs/issue67872.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2024 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 p

type A = uint8
type E uint8

func f[P ~A](P) {}

func g(e E) {
f(e)
}

0 comments on commit 0d478d8

Please sign in to comment.