diff options
author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2022-06-29 00:07:37 +0700 |
---|---|---|
committer | David Chase <drchase@google.com> | 2022-06-28 18:38:57 +0000 |
commit | 34f3ac5f165d50356d3a8940dc87b77e9b2b7fb9 (patch) | |
tree | 4dd2207eb38c3886d4e92bc1fd91b49c6f5ba5db | |
parent | 7df0a002e64e92f35db5a70e64345651ad2cbf97 (diff) | |
download | go-34f3ac5f165d50356d3a8940dc87b77e9b2b7fb9.tar.gz go-34f3ac5f165d50356d3a8940dc87b77e9b2b7fb9.zip |
cmd/compile: fix generic inter-inter comparisons from value switch statements
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>
-rw-r--r-- | src/cmd/compile/internal/noder/stencil.go | 4 | ||||
-rw-r--r-- | test/run.go | 1 |
2 files changed, 2 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index 89869c77d6..cf2f0b38db 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -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]) } } diff --git a/test/run.go b/test/run.go index 224d24db90..8934e23b38 100644 --- a/test/run.go +++ b/test/run.go @@ -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 |