From b516216f5fa91470eede5c752e5db0f957325030 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 1 Oct 2020 15:11:22 -0700 Subject: [PATCH] compiler: set varargs correctly for type of method expression Fixes golang/go#41737 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/258977 --- gcc/go/gofrontend/types.cc | 8 ++++++-- libgo/go/reflect/all_test.go | 8 +++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc index d6cd326b2e290..e3face89daeca 100644 --- a/gcc/go/gofrontend/types.cc +++ b/gcc/go/gofrontend/types.cc @@ -5350,8 +5350,12 @@ Function_type::copy_with_receiver_as_param(bool want_pointer_receiver) const ++p) new_params->push_back(*p); } - return Type::make_function_type(NULL, new_params, this->results_, - this->location_); + Function_type* ret = Type::make_function_type(NULL, new_params, + this->results_, + this->location_); + if (this->is_varargs_) + ret->set_is_varargs(); + return ret; } // Make a copy of a function type ignoring any receiver and adding a diff --git a/libgo/go/reflect/all_test.go b/libgo/go/reflect/all_test.go index e5ec052f7de74..6a6ec224cef98 100644 --- a/libgo/go/reflect/all_test.go +++ b/libgo/go/reflect/all_test.go @@ -2312,8 +2312,14 @@ func TestVariadicMethodValue(t *testing.T) { points := []Point{{20, 21}, {22, 23}, {24, 25}} want := int64(p.TotalDist(points[0], points[1], points[2])) + // Variadic method of type. + tfunc := TypeOf((func(Point, ...Point) int)(nil)) + if tt := TypeOf(p).Method(4).Type; tt != tfunc { + t.Errorf("Variadic Method Type from TypeOf is %s; want %s", tt, tfunc) + } + // Curried method of value. - tfunc := TypeOf((func(...Point) int)(nil)) + tfunc = TypeOf((func(...Point) int)(nil)) v := ValueOf(p).Method(4) if tt := v.Type(); tt != tfunc { t.Errorf("Variadic Method Type is %s; want %s", tt, tfunc)