cmd/compile: set correct package for vars/params/results from nested instantiation

Fixes #52117

Change-Id: Ib5b2cdbdbce1d516aa10a0df349449b756f2f404
Reviewed-on: https://go-review.googlesource.com/c/go/+/398474
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Cuong Manh Le 2022-04-05 23:33:58 +07:00 committed by Matthew Dempsky
parent 74f0009422
commit c90a19a760
4 changed files with 39 additions and 0 deletions

View file

@ -417,6 +417,7 @@ func (g *genInst) buildClosure(outer *ir.Func, x ir.Node) ir.Node {
var dictAssign *ir.AssignStmt
if outer != nil {
dictVar = ir.NewNameAt(pos, typecheck.LookupNum(typecheck.LocalDictName, g.dnum))
dictVar.SetSym(outer.Sym().Pkg.Lookup(dictVar.Sym().Name))
g.dnum++
dictVar.Class = ir.PAUTO
typed(types.Types[types.TUINTPTR], dictVar)
@ -431,6 +432,9 @@ func (g *genInst) buildClosure(outer *ir.Func, x ir.Node) ir.Node {
var rcvrAssign ir.Node
if rcvrValue != nil {
rcvrVar = ir.NewNameAt(pos, typecheck.LookupNum(".rcvr", g.dnum))
if outer != nil {
rcvrVar.SetSym(outer.Sym().Pkg.Lookup(rcvrVar.Sym().Name))
}
g.dnum++
typed(rcvrValue.Type(), rcvrVar)
rcvrAssign = ir.NewAssignStmt(pos, rcvrVar, rcvrValue)
@ -2222,6 +2226,9 @@ func startClosure(pos src.XPos, outer *ir.Func, typ *types.Type) (*ir.Func, []*t
for i := 0; i < typ.NumParams(); i++ {
t := typ.Params().Field(i).Type
arg := ir.NewNameAt(pos, typecheck.LookupNum("a", i))
if outer != nil {
arg.SetSym(outer.Sym().Pkg.Lookup(arg.Sym().Name))
}
arg.Class = ir.PPARAM
typed(t, arg)
arg.Curfn = fn
@ -2234,6 +2241,9 @@ func startClosure(pos src.XPos, outer *ir.Func, typ *types.Type) (*ir.Func, []*t
for i := 0; i < typ.NumResults(); i++ {
t := typ.Results().Field(i).Type
result := ir.NewNameAt(pos, typecheck.LookupNum("r", i)) // TODO: names not needed?
if outer != nil {
result.SetSym(outer.Sym().Pkg.Lookup(result.Sym().Name))
}
result.Class = ir.PPARAMOUT
typed(t, result)
result.Curfn = fn

View file

@ -0,0 +1,15 @@
// 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 a
func Compare[T int | uint](a, b T) int {
return 0
}
type Slice[T int | uint] struct{}
func (l Slice[T]) Comparator() func(v1, v2 T) int {
return Compare[T]
}

View file

@ -0,0 +1,7 @@
package b
import "./a"
func Test() {
var _ a.Slice[uint]
}

View file

@ -0,0 +1,7 @@
// compiledir
// 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 ignored