Skip to content

Commit 460a93b

Browse files
cuonglmheschi
authored andcommitted
[release-branch.go1.18] 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 #53357 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]> Reviewed-on: https://go-review.googlesource.com/c/go/+/411934 Reviewed-by: Keith Randall <[email protected]>
1 parent 3da88c0 commit 460a93b

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,10 +1297,10 @@ func (g *genInst) dictPass(info *instInfo) {
12971297
m = convertUsingDictionary(info, info.dictParam, m.Pos(), mce.X, m, m.Type(), false)
12981298
}
12991299
case ir.ODOTTYPE, ir.ODOTTYPE2:
1300-
if !m.Type().HasShape() {
1300+
dt := m.(*ir.TypeAssertExpr)
1301+
if !dt.Type().HasShape() && !dt.X.Type().HasShape() {
13011302
break
13021303
}
1303-
dt := m.(*ir.TypeAssertExpr)
13041304
var rt ir.Node
13051305
if dt.Type().IsInterface() || dt.X.Type().IsEmptyInterface() {
13061306
ix := findDictType(info, m.Type())

test/typeparam/issue53309.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// run -gcflags=-G=3
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)