cmd/compile: fix wrong dict pass condition for type assertions

Fixes #54135

Change-Id: I2b27af8124014b2699ea44bdc765e1fb8f6c8028
Reviewed-on: https://go-review.googlesource.com/c/go/+/420394
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Wayne Zuo 2022-07-31 17:20:26 +08:00 committed by Matthew Dempsky
parent e99f53fed9
commit 27038b70f8
2 changed files with 31 additions and 0 deletions

View file

@ -1357,6 +1357,9 @@ func (g *genInst) dictPass(info *instInfo) {
}
case ir.ODOTTYPE, ir.ODOTTYPE2:
dt := m.(*ir.TypeAssertExpr)
if dt.Type().IsEmptyInterface() || (dt.Type().IsInterface() && !dt.Type().HasShape()) {
break
}
if !dt.Type().HasShape() && !(dt.X.Type().HasShape() && !dt.X.Type().IsEmptyInterface()) {
break
}

View file

@ -0,0 +1,28 @@
// 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 Foo struct{}
func (Foo) Blanker() {}
type Bar[T any] interface {
Blanker()
}
type Baz interface {
Some()
}
func check[T comparable](p Bar[T]) {
_, _ = p.(any)
_, _ = p.(Baz)
}
func main() {
check[int](Foo{})
}