]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
compiler: set varargs correctly for type of method expression
authorIan Lance Taylor <iant@golang.org>
Thu, 1 Oct 2020 22:11:22 +0000 (15:11 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 1 Oct 2020 23:31:36 +0000 (16:31 -0700)
Fixes golang/go#41737

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/258977

gcc/go/gofrontend/types.cc
libgo/go/reflect/all_test.go

index d6cd326b2e290b344cd7b40efd7b0a8babfa4a78..e3face89daeca20346eb2fbd40ed38541f09d1ea 100644 (file)
@@ -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
index e5ec052f7de74404353e48b37ff87e72282e87c3..6a6ec224cef98463c2b0db8854933f0914cfeae4 100644 (file)
@@ -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)