diff options
author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2022-06-11 01:33:11 +0700 |
---|---|---|
committer | Heschi Kreinick <heschi@google.com> | 2022-07-06 19:31:41 +0000 |
commit | 460a93b54af4a0305f6007e44e41e6160a6469d8 (patch) | |
tree | f45e3b0e5d6564caaa6b65e0c9848bda11ca9315 | |
parent | 3da88c0bdc94f8cacc5cef3026a7e256109e616d (diff) | |
download | go-460a93b54af4a0305f6007e44e41e6160a6469d8.tar.gz go-460a93b54af4a0305f6007e44e41e6160a6469d8.zip |
[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 <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>
Reviewed-on: https://go-review.googlesource.com/c/go/+/411934
Reviewed-by: Keith Randall <khr@google.com>
-rw-r--r-- | src/cmd/compile/internal/noder/stencil.go | 4 | ||||
-rw-r--r-- | test/typeparam/issue53309.go | 42 |
2 files changed, 44 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index 58b7b9e8ddf..7cfd70ec546 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -1297,10 +1297,10 @@ func (g *genInst) dictPass(info *instInfo) { m = convertUsingDictionary(info, info.dictParam, m.Pos(), mce.X, m, m.Type(), false) } 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 rt ir.Node if dt.Type().IsInterface() || dt.X.Type().IsEmptyInterface() { ix := findDictType(info, m.Type()) diff --git a/test/typeparam/issue53309.go b/test/typeparam/issue53309.go new file mode 100644 index 00000000000..d505f6b58a6 --- /dev/null +++ b/test/typeparam/issue53309.go @@ -0,0 +1,42 @@ +// run -gcflags=-G=3 + +// 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)) +} |