Skip to content

Commit 8cf1169

Browse files
committed
cmd/compile: fix transform of OEQ/ONE when one arg is a type param
At this point in stenciling, we have shape types, not raw type parameters. The code was correct in the other part of this function. Update golang#51522 Change-Id: Ife495160a2be5f6af5400363c3efb68dda518b5f Reviewed-on: https://go-review.googlesource.com/c/go/+/391475 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 parent 91daaab commit 8cf1169

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func transformCompare(n *ir.BinaryExpr) {
242242
aop, _ := typecheck.Assignop(rt, lt)
243243
if aop != ir.OXXX {
244244
types.CalcSize(rt)
245-
if rt.HasTParam() || rt.IsInterface() == lt.IsInterface() || rt.Size() >= 1<<16 {
245+
if rt.HasShape() || rt.IsInterface() == lt.IsInterface() || rt.Size() >= 1<<16 {
246246
r = ir.NewConvExpr(base.Pos, aop, lt, r)
247247
r.SetTypecheck(1)
248248
}

test/typeparam/issue51522a.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// run
2+
3+
// Copyright 2022 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+
package main
7+
8+
9+
func f[T comparable](i any) {
10+
var t T
11+
12+
if i != t {
13+
println("FAIL: if i != t")
14+
}
15+
}
16+
17+
type myint int
18+
19+
func (m myint) foo() {
20+
}
21+
22+
type fooer interface {
23+
foo()
24+
}
25+
26+
type comparableFoo interface {
27+
comparable
28+
foo()
29+
}
30+
31+
func g[T comparableFoo](i fooer) {
32+
var t T
33+
34+
if i != t {
35+
println("FAIL: if i != t")
36+
}
37+
}
38+
39+
func main() {
40+
f[int](int(0))
41+
g[myint](myint(0))
42+
}

0 commit comments

Comments
 (0)