if m.Tag != nil && m.Tag.Op() == ir.OTYPESW {
break // Nothing to do here for type switches.
}
- if m.Tag != nil && !m.Tag.Type().IsInterface() && m.Tag.Type().HasShape() {
+ if m.Tag != nil && !m.Tag.Type().IsEmptyInterface() && m.Tag.Type().HasShape() {
// To implement a switch on a value that is or has a type parameter, we first convert
// that thing we're switching on to an interface{}.
m.Tag = assignconvfn(m.Tag, types.Types[types.TINTER])
for i, x := range c.List {
// If we have a case that is or has a type parameter, convert that case
// to an interface{}.
- if !x.Type().IsInterface() && x.Type().HasShape() {
+ if !x.Type().IsEmptyInterface() && x.Type().HasShape() {
c.List[i] = assignconvfn(x, types.Types[types.TINTER])
}
}
--- /dev/null
+// run -gcflags=-G=3
+
+// Copyright 2022 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.
+
+// Test that generic interface-interface comparisons resulting from
+// value switch statements are handled correctly.
+
+package main
+
+func main() {
+ f[X](0)
+}
+
+type Mer[T any] interface{ M(T) }
+type MNer[T any] interface {
+ Mer[T]
+ N()
+}
+
+type X int
+
+func (X) M(X) {}
+func (X) N() {}
+
+func f[T MNer[T]](t T) {
+ switch Mer[T](t) {
+ case MNer[T](t):
+ // ok
+ default:
+ panic("FAIL")
+ }
+}