Skip to content

Commit 0c4db1e

Browse files
mdempskygopherbot
authored andcommitted
cmd/compile: fix import/export of ODYNAMICDOTTYPE
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 <[email protected]> Run-TryBot: Matthew Dempsky <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> Reviewed-by: Keith Randall <[email protected]> Auto-Submit: Matthew Dempsky <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent d75e186 commit 0c4db1e

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

src/cmd/compile/internal/typecheck/iexport.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,9 @@ func (w *exportWriter) expr(n ir.Node) {
19281928
w.op(n.Op())
19291929
w.pos(n.Pos())
19301930
w.expr(n.X)
1931-
w.expr(n.RType)
1931+
if w.bool(n.RType != nil) {
1932+
w.expr(n.RType)
1933+
}
19321934
if w.bool(n.ITab != nil) {
19331935
w.expr(n.ITab)
19341936
}

src/cmd/compile/internal/typecheck/iimport.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,10 @@ func (r *importReader) node() ir.Node {
14601460
return n
14611461

14621462
case ir.ODYNAMICDOTTYPE, ir.ODYNAMICDOTTYPE2:
1463-
n := ir.NewDynamicTypeAssertExpr(r.pos(), op, r.expr(), r.expr())
1463+
n := ir.NewDynamicTypeAssertExpr(r.pos(), op, r.expr(), nil)
1464+
if r.bool() {
1465+
n.RType = r.expr()
1466+
}
14641467
if r.bool() {
14651468
n.ITab = r.expr()
14661469
}

test/typeparam/issue54302.dir/a.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package a
6+
7+
func A() {
8+
B[int](new(G[int]))
9+
}
10+
11+
func B[T any](iface interface{ M(T) }) {
12+
x, ok := iface.(*G[T])
13+
if !ok || iface != x {
14+
panic("FAIL")
15+
}
16+
}
17+
18+
type G[T any] struct{}
19+
20+
func (*G[T]) M(T) {}

test/typeparam/issue54302.dir/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import "./a"
8+
9+
func main() {
10+
a.A()
11+
}

test/typeparam/issue54302.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// rundir
2+
3+
// Copyright 2022 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package p

0 commit comments

Comments
 (0)