Skip to content

Commit 7eeec1f

Browse files
cuonglmrandall77
authored andcommitted
cmd/compile: fix missing dict pass for type assertions
For type assertions, if either src or dst type has shape, we must convert them to dynamic type assertions. Fixes #53309 Change-Id: Ia3362fa67c011febcbdb5b26f856d081b5c366de Reviewed-on: https://go-review.googlesource.com/c/go/+/411617 Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent d27128b commit 7eeec1f

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,10 +1330,10 @@ func (g *genInst) dictPass(info *instInfo) {
13301330
m = convertUsingDictionary(info, info.dictParam, m.Pos(), mce.X, m, m.Type())
13311331
}
13321332
case ir.ODOTTYPE, ir.ODOTTYPE2:
1333-
if !m.Type().HasShape() {
1333+
dt := m.(*ir.TypeAssertExpr)
1334+
if !dt.Type().HasShape() && !dt.X.Type().HasShape() {
13341335
break
13351336
}
1336-
dt := m.(*ir.TypeAssertExpr)
13371337
var rtype, itab ir.Node
13381338
if dt.Type().IsInterface() || dt.X.Type().IsEmptyInterface() {
13391339
// TODO(mdempsky): Investigate executing this block unconditionally.

test/fixedbugs/issue53309.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// run
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 TaskInput interface {
10+
deps() []*taskDefinition
11+
}
12+
13+
type Value[T any] interface {
14+
metaValue
15+
}
16+
17+
type metaValue interface {
18+
TaskInput
19+
}
20+
21+
type taskDefinition struct {
22+
}
23+
24+
type taskResult struct {
25+
task *taskDefinition
26+
}
27+
28+
func (tr *taskResult) deps() []*taskDefinition {
29+
return nil
30+
}
31+
32+
func use[T any](v Value[T]) {
33+
_, ok := v.(*taskResult)
34+
if !ok {
35+
panic("output must be *taskResult")
36+
}
37+
}
38+
39+
func main() {
40+
tr := &taskResult{&taskDefinition{}}
41+
use(Value[string](tr))
42+
}

0 commit comments

Comments
 (0)