1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:04:42 -07:00

go/types: permit f(nil...) for variadic arguments

This code may be pointless, but it is legal.

Fixes golang/go#18268

Change-Id: Ibacae583606e1a6fdf0c0f01abe2e22e9e608393
Reviewed-on: https://go-review.googlesource.com/34194
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Alan Donovan 2016-12-09 09:55:50 -05:00 committed by Russ Cox
parent a855da29db
commit 08bb7ccb75
2 changed files with 2 additions and 1 deletions

View File

@ -250,7 +250,7 @@ func (check *Checker) argument(fun ast.Expr, sig *Signature, i int, x *operand,
check.errorf(ellipsis, "can only use ... with matching parameter") check.errorf(ellipsis, "can only use ... with matching parameter")
return return
} }
if _, ok := x.typ.Underlying().(*Slice); !ok { if _, ok := x.typ.Underlying().(*Slice); !ok && x.typ != Typ[UntypedNil] { // see issue #18268
check.errorf(x.pos(), "cannot use %s as parameter of type %s", x, typ) check.errorf(x.pos(), "cannot use %s as parameter of type %s", x, typ)
return return
} }

View File

@ -19,6 +19,7 @@ func append1() {
_ = append(nil /* ERROR not a slice */ , s) _ = append(nil /* ERROR not a slice */ , s)
_ = append(x /* ERROR not a slice */ , s) _ = append(x /* ERROR not a slice */ , s)
_ = append(s) _ = append(s)
_ = append(s, nil...)
append /* ERROR not used */ (s) append /* ERROR not used */ (s)
_ = append(s, b) _ = append(s, b)