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 #54309.
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>
(cherry picked from commit
0c4db1e347dc51589e5289388305b02108ca0aa1)
Reviewed-on: https://go-review.googlesource.com/c/go/+/421715
Reviewed-by: Than McIntosh <thanm@google.com>
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)
}
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()
}
--- /dev/null
+// 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) {}
--- /dev/null
+// 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()
+}
--- /dev/null
+// 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