Skip to content

Commit

Permalink
compiler: set varargs correctly for type of method expression
Browse files Browse the repository at this point in the history
  • Loading branch information
ianlancetaylor committed Oct 1, 2020
1 parent 84dc387 commit b516216
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions gcc/go/gofrontend/types.cc
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion libgo/go/reflect/all_test.go
Expand Up @@ -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)
Expand Down

0 comments on commit b516216

Please sign in to comment.