From bee0c739007617c840ac29a6f8fcf9f24cbf1505 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Mon, 8 Nov 2021 13:08:58 +0700 Subject: [PATCH] cmd/compile: fix irgen mis-handling of ... argument when creating closure 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 Trust: Dan Scales Run-TryBot: Cuong Manh Le TryBot-Result: Go Bot Reviewed-by: Dan Scales --- src/cmd/compile/internal/noder/stencil.go | 1 + test/typeparam/issue49432.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/typeparam/issue49432.go diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index 74281bc479..4ebd607c16 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -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 index 0000000000..21d6ec4b70 --- /dev/null +++ b/test/typeparam/issue49432.go @@ -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() +} -- 2.50.0