Skip to content

Commit

Permalink
cmd/compile: don't use dictionary convert to shaped empty interface
Browse files Browse the repository at this point in the history
Fixes: golang#53254

Change-Id: I3153d6ebb9f25957b09363f45c5cd4651ee84c2d
Reviewed-on: https://go-review.googlesource.com/c/go/+/410655
Reviewed-by: Matthew Dempsky <[email protected]>
Run-TryBot: Wayne Zuo <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
  • Loading branch information
wdvxdr1123 authored and randall77 committed Jun 22, 2022
1 parent 2a3b467 commit ff17b7d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/noder/stencil.go
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ func (g *genInst) dictPass(info *instInfo) {
mce := m.(*ir.ConvExpr)
// Note: x's argument is still typed as a type parameter.
// m's argument now has an instantiated type.
if mce.X.Type().HasShape() || m.Type().HasShape() {
if mce.X.Type().HasShape() || (m.Type().HasShape() && !m.Type().IsEmptyInterface()) {
m = convertUsingDictionary(info, info.dictParam, m.Pos(), mce.X, m, m.Type())
}
case ir.ODOTTYPE, ir.ODOTTYPE2:
Expand Down Expand Up @@ -1446,7 +1446,7 @@ func findDictType(info *instInfo, t *types.Type) int {
// instantiated node of the CONVIFACE node or XDOT node (for a bound method call) that is causing the
// conversion.
func convertUsingDictionary(info *instInfo, dictParam *ir.Name, pos src.XPos, v ir.Node, in ir.Node, dst *types.Type) ir.Node {
assert(v.Type().HasShape() || in.Type().HasShape())
assert(v.Type().HasShape() || (in.Type().HasShape() && !in.Type().IsEmptyInterface()))
assert(dst.IsInterface())

if v.Type().IsInterface() {
Expand Down
19 changes: 19 additions & 0 deletions test/typeparam/issue53254.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 Interface[T any] interface {
}

func F[T any]() Interface[T] {
var i int
return i
}

func main() {
F[int]()
}

0 comments on commit ff17b7d

Please sign in to comment.