]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix generic inter-inter comparisons from value switch statements
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 28 Jun 2022 17:07:37 +0000 (00:07 +0700)
committerDavid Chase <drchase@google.com>
Tue, 28 Jun 2022 18:38:57 +0000 (18:38 +0000)
If value is a non-empty interface and has shape, we still need to
convert it to an interface{} first.

Fixes #53477

Change-Id: I516063ba4429a6cc24c483758387ec13815fc63e
Reviewed-on: https://go-review.googlesource.com/c/go/+/414834
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>

src/cmd/compile/internal/noder/stencil.go
test/run.go

index 89869c77d6ce47b5643944f098c1cb06eec7044c..cf2f0b38db3e85c522dee02ace88b70c8cdf2846 100644 (file)
@@ -1214,7 +1214,7 @@ func (subst *subster) node(n ir.Node) ir.Node {
                        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])
@@ -1223,7 +1223,7 @@ func (subst *subster) node(n ir.Node) ir.Node {
                                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])
                                        }
                                }
index 224d24db90624120417796ece7641fa9b5d0e0b4..8934e23b3857a1a64a2f5e9bd932626a459438be 100644 (file)
@@ -1967,7 +1967,6 @@ var go118Failures = setOf(
        "typeparam/nested.go",     // 1.18 compiler doesn't support function-local types with generics
        "typeparam/issue51521.go", // 1.18 compiler produces bad panic message and link error
        "typeparam/issue53419.go", // 1.18 compiler mishandles generic selector resolution
-       "typeparam/issue53477.go", // 1.18 compiler mishandles generic interface-interface comparisons from value switch statements
 )
 
 // In all of these cases, the 1.17 compiler reports reasonable errors, but either the