mirror of
https://github.com/golang/go
synced 2024-10-02 22:25:08 +00:00
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:
parent
e99f53fed9
commit
27038b70f8
|
@ -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
|
||||
}
|
||||
|
|
28
test/typeparam/issue54135.go
Normal file
28
test/typeparam/issue54135.go
Normal 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{})
|
||||
}
|
Loading…
Reference in a new issue