Skip to content

Commit

Permalink
cmd/compile: fix type assert in dict pass
Browse files Browse the repository at this point in the history
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 <wdvxdr@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
  • Loading branch information
wdvxdr1123 authored and heschi committed Jul 13, 2022
1 parent bf2ef26 commit 923740a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/noder/stencil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions test/typeparam/issue53762.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 923740a

Please # to comment.