]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix irgen mis-handling of ... argument when creating closure
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 8 Nov 2021 06:08:58 +0000 (13:08 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 9 Nov 2021 00:08:09 +0000 (00:08 +0000)
When bulding formal arguments of newly created closure, irgen forgets to
set "..." field attribute, causing type mismatched between the closure
function and the ONAME node represents that closure function.

Fixes #49432

Change-Id: Ieddaa64980cdd3d8cea236a5a9de0204ee21ee39
Reviewed-on: https://go-review.googlesource.com/c/go/+/361961
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
src/cmd/compile/internal/noder/stencil.go
test/typeparam/issue49432.go [new file with mode: 0644]

index 74281bc479135f0bb1e3e3985c8c9367d98394fb..4ebd607c160d65c3f296eb1413aab59d1a7ca1a4 100644 (file)
@@ -2085,6 +2085,7 @@ func startClosure(pos src.XPos, outer *ir.Func, typ *types.Type) (*ir.Func, []*t
                fn.Dcl = append(fn.Dcl, arg)
                f := types.NewField(pos, arg.Sym(), t)
                f.Nname = arg
+               f.SetIsDDD(typ.Params().Field(i).IsDDD())
                formalParams = append(formalParams, f)
        }
        for i := 0; i < typ.NumResults(); i++ {
diff --git a/test/typeparam/issue49432.go b/test/typeparam/issue49432.go
new file mode 100644 (file)
index 0000000..21d6ec4
--- /dev/null
@@ -0,0 +1,22 @@
+// compile -G=3
+
+// Copyright 2021 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 Handler func(in ...interface{})
+
+type Foo[T any] struct{}
+
+func (b *Foo[T]) Bar(in ...interface{}) {}
+
+func (b *Foo[T]) Init() {
+       _ = Handler(b.Bar)
+}
+
+func main() {
+       c := &Foo[int]{}
+       c.Init()
+}