From 923740a8cc82e0bd3cd6098f94130b1967c4b361 Mon Sep 17 00:00:00 2001 From: Wayne Zuo Date: Sun, 10 Jul 2022 11:11:05 +0800 Subject: [PATCH] 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 TryBot-Result: Gopher Robot Reviewed-by: Matthew Dempsky Reviewed-by: Michael Knyszek --- src/cmd/compile/internal/noder/stencil.go | 2 +- test/typeparam/issue53762.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/typeparam/issue53762.go diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index 1534a1fa49..1ba561b8b9 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -1357,7 +1357,7 @@ func (g *genInst) dictPass(info *instInfo) { } case ir.ODOTTYPE, ir.ODOTTYPE2: dt := m.(*ir.TypeAssertExpr) - if !dt.Type().HasShape() && !dt.X.Type().HasShape() { + if !dt.Type().HasShape() && !(dt.X.Type().HasShape() && !dt.X.Type().IsEmptyInterface()) { break } var rtype, itab ir.Node diff --git a/test/typeparam/issue53762.go b/test/typeparam/issue53762.go new file mode 100644 index 0000000000..4d95988854 --- /dev/null +++ b/test/typeparam/issue53762.go @@ -0,0 +1,18 @@ +// compile + +// 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 Value[T any] interface { +} + +func use[T any](v Value[T]) { + _, _ = v.(int) +} + +func main() { + use(Value[int](1)) +}