]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix type assert in dict pass
authorWayne Zuo <wdvxdr@golangcn.org>
Sun, 10 Jul 2022 03:11:05 +0000 (11:11 +0800)
committerHeschi Kreinick <heschi@google.com>
Wed, 13 Jul 2022 16:06:45 +0000 (16:06 +0000)
For type assertions, if src type is empty interface, we should
use normal type assertions rather than dynamic type assertions.

Fixes #53762

Change-Id: I596b2e4ad647fe5e42ad884f7273c78f8f50dac2
Reviewed-on: https://go-review.googlesource.com/c/go/+/416736
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/cmd/compile/internal/noder/stencil.go
test/typeparam/issue53762.go [new file with mode: 0644]

index 1534a1fa49ccfd3b4c475839e340baafa68b7ec0..1ba561b8b960d61259fb3abbb8cee95999815ac8 100644 (file)
@@ -1357,7 +1357,7 @@ func (g *genInst) dictPass(info *instInfo) {
                        }
                case ir.ODOTTYPE, ir.ODOTTYPE2:
                        dt := m.(*ir.TypeAssertExpr)
-                       if !dt.Type().HasShape() && !dt.X.Type().HasShape() {
+                       if !dt.Type().HasShape() && !(dt.X.Type().HasShape() && !dt.X.Type().IsEmptyInterface()) {
                                break
                        }
                        var rtype, itab ir.Node
diff --git a/test/typeparam/issue53762.go b/test/typeparam/issue53762.go
new file mode 100644 (file)
index 0000000..4d95988
--- /dev/null
@@ -0,0 +1,18 @@
+// compile
+
+// 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.
+
+package main
+
+type Value[T any] interface {
+}
+
+func use[T any](v Value[T]) {
+       _, _ = v.(int)
+}
+
+func main() {
+       use(Value[int](1))
+}