Skip to content

Commit ffd232f

Browse files
committed
Require named arguments after * in argument list
1 parent 02596cc commit ffd232f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/antlr/Python3.g4

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,11 @@ typedargslist [ArgDefListBuilder args]
544544
( ',' ( kwargsparameter[args] ','? )? )?
545545
| kwargsparameter[args] ','?
546546
)
547+
{
548+
if (!args.validateArgumentsAfterSplat()) {
549+
throw new PythonRecognitionException("named arguments must follow bare *", this, _input, $ctx, getCurrentToken());
550+
}
551+
}
547552
;
548553

549554
defparameter [ArgDefListBuilder args]
@@ -609,6 +614,11 @@ varargslist returns [ArgDefListBuilder result]
609614
( ',' (vkwargsparameter[args] ','? )? )?
610615
| vkwargsparameter[args] ','?
611616
)
617+
{
618+
if (!args.validateArgumentsAfterSplat()) {
619+
throw new PythonRecognitionException("named arguments must follow bare *", this, _input, $ctx, getCurrentToken());
620+
}
621+
}
612622
{ $result = args; }
613623
;
614624

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/sst/ArgDefListBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ public boolean hasSplat() {
213213
return splatIndex > -1;
214214
}
215215

216+
public boolean validateArgumentsAfterSplat() {
217+
return !(splatIndex > -1 && args != null && args.get(splatIndex).name == null && paramNames.size() <= splatIndex);
218+
}
219+
216220
/**
217221
*
218222
* @return The index to the positional only argument marker ('/'). Which means that all

0 commit comments

Comments
 (0)