Skip to content

Commit 923740a

Browse files
wdvxdr1123heschi
authored andcommitted
cmd/compile: fix type assert in dict pass
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent bf2ef26 commit 923740a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/cmd/compile/internal/noder/stencil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ func (g *genInst) dictPass(info *instInfo) {
13571357
}
13581358
case ir.ODOTTYPE, ir.ODOTTYPE2:
13591359
dt := m.(*ir.TypeAssertExpr)
1360-
if !dt.Type().HasShape() && !dt.X.Type().HasShape() {
1360+
if !dt.Type().HasShape() && !(dt.X.Type().HasShape() && !dt.X.Type().IsEmptyInterface()) {
13611361
break
13621362
}
13631363
var rtype, itab ir.Node

test/typeparam/issue53762.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// compile
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 main
8+
9+
type Value[T any] interface {
10+
}
11+
12+
func use[T any](v Value[T]) {
13+
_, _ = v.(int)
14+
}
15+
16+
func main() {
17+
use(Value[int](1))
18+
}

0 commit comments

Comments
 (0)