mirror of
https://github.com/golang/go
synced 2024-09-05 16:04:50 +00:00
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 <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
d27128b065
commit
7eeec1f6e4
|
@ -1330,10 +1330,10 @@ func (g *genInst) dictPass(info *instInfo) {
|
|||
m = convertUsingDictionary(info, info.dictParam, m.Pos(), mce.X, m, m.Type())
|
||||
}
|
||||
case ir.ODOTTYPE, ir.ODOTTYPE2:
|
||||
if !m.Type().HasShape() {
|
||||
dt := m.(*ir.TypeAssertExpr)
|
||||
if !dt.Type().HasShape() && !dt.X.Type().HasShape() {
|
||||
break
|
||||
}
|
||||
dt := m.(*ir.TypeAssertExpr)
|
||||
var rtype, itab ir.Node
|
||||
if dt.Type().IsInterface() || dt.X.Type().IsEmptyInterface() {
|
||||
// TODO(mdempsky): Investigate executing this block unconditionally.
|
||||
|
|
42
test/fixedbugs/issue53309.go
Normal file
42
test/fixedbugs/issue53309.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
// run
|
||||
|
||||
// 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
|
||||
|
||||
type TaskInput interface {
|
||||
deps() []*taskDefinition
|
||||
}
|
||||
|
||||
type Value[T any] interface {
|
||||
metaValue
|
||||
}
|
||||
|
||||
type metaValue interface {
|
||||
TaskInput
|
||||
}
|
||||
|
||||
type taskDefinition struct {
|
||||
}
|
||||
|
||||
type taskResult struct {
|
||||
task *taskDefinition
|
||||
}
|
||||
|
||||
func (tr *taskResult) deps() []*taskDefinition {
|
||||
return nil
|
||||
}
|
||||
|
||||
func use[T any](v Value[T]) {
|
||||
_, ok := v.(*taskResult)
|
||||
if !ok {
|
||||
panic("output must be *taskResult")
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
tr := &taskResult{&taskDefinition{}}
|
||||
use(Value[string](tr))
|
||||
}
|
Loading…
Reference in a new issue