Fixes #423.
R=ken2
https://golang.org/cl/180045
}
NodeList*
-checkarglist(NodeList *all)
+checkarglist(NodeList *all, int input)
{
int named;
Node *n, *t, *nextt;
if(n != N)
n = newname(n->sym);
n = nod(ODCLFIELD, n, t);
- if(l->next != nil && n->right != N && n->right->op == OTYPE && isddd(n->right->type))
- yyerror("only last argument can have type ...");
+ if(n->right != N && n->right->op == OTYPE && isddd(n->right->type)) {
+ if(!input)
+ yyerror("cannot use ... in output argument list");
+ else if(l->next != nil)
+ yyerror("can only use ... as final argument in list");
+ }
l->n = n;
}
return all;
Type* oldtype(Sym*);
void fninit(NodeList*);
Node* nametodcl(Node*, Type*);
-NodeList* checkarglist(NodeList*);
+NodeList* checkarglist(NodeList*, int);
void checkwidth(Type*);
void defercheckwidth(void);
void resumecheckwidth(void);
{
Node *n;
+ $3 = checkarglist($3, 1);
$$ = nod(ODCLFUNC, N, N);
$$->nname = $1;
if($3 == nil && $5 == nil)
{
Node *rcvr, *t;
+ $2 = checkarglist($2, 0);
+ $6 = checkarglist($6, 1);
$$ = N;
if($2 == nil) {
yyerror("method has no receiver");
fntype:
LFUNC '(' oarg_type_list_ocomma ')' fnres
{
+ $3 = checkarglist($3, 1);
$$ = nod(OTFUNC, N, N);
$$->list = $3;
$$->rlist = $5;
}
| '(' oarg_type_list_ocomma ')'
{
+ $2 = checkarglist($2, 0);
$$ = $2;
}
'(' oarg_type_list_ocomma ')' fnres
{
// without func keyword
+ $2 = checkarglist($2, 0);
$$ = nod(OTFUNC, fakethis(), N);
$$->list = $2;
$$->rlist = $4;
}
| arg_type_list ocomma
{
- $$ = checkarglist($1);
+ $$ = $1;
}
/*
--- /dev/null
+// errchk $G -e $D/$F.go
+
+// Copyright 2009 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
+
+func f(x int, y ...) // ok
+
+func g(x int, y float) (...) // ERROR "[.][.][.]"
+
+func h(x, y ...) // ERROR "[.][.][.]"
+
+func i(x int, y ..., z float) // ERROR "[.][.][.]"
+
+var x ...; // ERROR "[.][.][.]|syntax"
+
+type T ...; // ERROR "[.][.][.]|syntax"