]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.18] cmd/compile: set correct package for vars/params/results...
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 5 Apr 2022 16:33:58 +0000 (23:33 +0700)
committerHeschi Kreinick <heschi@google.com>
Mon, 9 May 2022 20:13:36 +0000 (20:13 +0000)
Fixes #52606

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>
Reviewed-on: https://go-review.googlesource.com/c/go/+/403174

src/cmd/compile/internal/noder/stencil.go
test/typeparam/issue52117.dir/a.go [new file with mode: 0644]
test/typeparam/issue52117.dir/b.go [new file with mode: 0644]
test/typeparam/issue52117.go [new file with mode: 0644]

index 39185ad7f46ccf4698aa17dd150b76883dbd7b7b..58b7b9e8ddfaccce5d5dd05c45a934c26cf2d277 100644 (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)
@@ -2111,6 +2115,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
@@ -2123,6 +2130,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
diff --git a/test/typeparam/issue52117.dir/a.go b/test/typeparam/issue52117.dir/a.go
new file mode 100644 (file)
index 0000000..e571ea9
--- /dev/null
@@ -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]
+}
diff --git a/test/typeparam/issue52117.dir/b.go b/test/typeparam/issue52117.dir/b.go
new file mode 100644 (file)
index 0000000..3d3bf4c
--- /dev/null
@@ -0,0 +1,7 @@
+package b
+
+import "./a"
+
+func Test() {
+       var _ a.Slice[uint]
+}
diff --git a/test/typeparam/issue52117.go b/test/typeparam/issue52117.go
new file mode 100644 (file)
index 0000000..060a121
--- /dev/null
@@ -0,0 +1,7 @@
+// compiledir -G=3
+
+// 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