Skip to content

Commit ec7bf20

Browse files
wdvxdr1123dmitshur
authored andcommitted
[release-branch.go1.19] cmd/compile: fix wrong dict pass condition for type assertions
Updates #54135. Change-Id: I2b27af8124014b2699ea44bdc765e1fb8f6c8028 Reviewed-on: https://go-review.googlesource.com/c/go/+/420394 Reviewed-by: Keith Randall <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> Run-TryBot: Wayne Zuo <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> (cherry picked from commit 27038b7) Reviewed-on: https://go-review.googlesource.com/c/go/+/420674 Run-TryBot: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 46ab46c commit ec7bf20

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/cmd/compile/internal/noder/stencil.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,9 @@ func (g *genInst) dictPass(info *instInfo) {
13571357
}
13581358
case ir.ODOTTYPE, ir.ODOTTYPE2:
13591359
dt := m.(*ir.TypeAssertExpr)
1360+
if dt.Type().IsEmptyInterface() || (dt.Type().IsInterface() && !dt.Type().HasShape()) {
1361+
break
1362+
}
13601363
if !dt.Type().HasShape() && !(dt.X.Type().HasShape() && !dt.X.Type().IsEmptyInterface()) {
13611364
break
13621365
}

test/typeparam/issue54135.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// compile
2+
3+
// Copyright 2022 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
type Foo struct{}
10+
11+
func (Foo) Blanker() {}
12+
13+
type Bar[T any] interface {
14+
Blanker()
15+
}
16+
17+
type Baz interface {
18+
Some()
19+
}
20+
21+
func check[T comparable](p Bar[T]) {
22+
_, _ = p.(any)
23+
_, _ = p.(Baz)
24+
}
25+
26+
func main() {
27+
check[int](Foo{})
28+
}

0 commit comments

Comments
 (0)