]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix import/export of ODYNAMICDOTTYPE
authorMatthew Dempsky <mdempsky@google.com>
Fri, 5 Aug 2022 23:09:22 +0000 (16:09 -0700)
committerGopher Robot <gobot@golang.org>
Sat, 6 Aug 2022 15:20:00 +0000 (15:20 +0000)
The RType field isn't needed when performing type assertions from
non-empty interface types, because we use the ITab field instead. But
the inline body exporter didn't know to expect this.

It's possible we could use a single bool to distinguish whether
we're serializing the RType or ITab field, but using two is simpler
and seems safer.

Fixes #54302.

Change-Id: I9ddac72784fb2241fee0a0dee30493d868a2c259
Reviewed-on: https://go-review.googlesource.com/c/go/+/421755
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/typecheck/iexport.go
src/cmd/compile/internal/typecheck/iimport.go
test/typeparam/issue54302.dir/a.go [new file with mode: 0644]
test/typeparam/issue54302.dir/main.go [new file with mode: 0644]
test/typeparam/issue54302.go [new file with mode: 0644]

index 43ec7b80a096336d4237a6f6529609b7ae0d800d..f3af8f7ffec8548f109a579eb28e540e7dc15f1f 100644 (file)
@@ -1928,7 +1928,9 @@ func (w *exportWriter) expr(n ir.Node) {
                w.op(n.Op())
                w.pos(n.Pos())
                w.expr(n.X)
-               w.expr(n.RType)
+               if w.bool(n.RType != nil) {
+                       w.expr(n.RType)
+               }
                if w.bool(n.ITab != nil) {
                        w.expr(n.ITab)
                }
index 84c748f7f0d2741ab584bf3ed88a2050ed0aa7a5..51978de095cba6887401455ff0941917022d3984 100644 (file)
@@ -1460,7 +1460,10 @@ func (r *importReader) node() ir.Node {
                return n
 
        case ir.ODYNAMICDOTTYPE, ir.ODYNAMICDOTTYPE2:
-               n := ir.NewDynamicTypeAssertExpr(r.pos(), op, r.expr(), r.expr())
+               n := ir.NewDynamicTypeAssertExpr(r.pos(), op, r.expr(), nil)
+               if r.bool() {
+                       n.RType = r.expr()
+               }
                if r.bool() {
                        n.ITab = r.expr()
                }
diff --git a/test/typeparam/issue54302.dir/a.go b/test/typeparam/issue54302.dir/a.go
new file mode 100644 (file)
index 0000000..52875ab
--- /dev/null
@@ -0,0 +1,20 @@
+// 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 a
+
+func A() {
+       B[int](new(G[int]))
+}
+
+func B[T any](iface interface{ M(T) }) {
+       x, ok := iface.(*G[T])
+       if !ok || iface != x {
+               panic("FAIL")
+       }
+}
+
+type G[T any] struct{}
+
+func (*G[T]) M(T) {}
diff --git a/test/typeparam/issue54302.dir/main.go b/test/typeparam/issue54302.dir/main.go
new file mode 100644 (file)
index 0000000..b4c6cd1
--- /dev/null
@@ -0,0 +1,11 @@
+// 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
+
+import "./a"
+
+func main() {
+       a.A()
+}
diff --git a/test/typeparam/issue54302.go b/test/typeparam/issue54302.go
new file mode 100644 (file)
index 0000000..f132421
--- /dev/null
@@ -0,0 +1,7 @@
+// rundir
+
+// 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 p