Skip to content

Commit 4298110

Browse files
committed
[GR-9814] fix lambda def arglist parsing when no args are specified
PullRequest: graalpython-open/51
2 parents 08dfee5 + 3b927a2 commit 4298110

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_parser.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,12 @@ def x(*, a=None, b):
6363
retval = x(b=42)
6464
""", globs)
6565
assert globs["retval"] == (None, 42)
66+
67+
68+
def test_lambda_no_args_with_nested_lambdas():
69+
no_err = True
70+
try:
71+
eval("lambda: ((lambda args: args[0], ), (lambda args: args[1], ), )")
72+
except Exception as e:
73+
no_err = False
74+
assert no_err

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/ScopeTranslator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ public T visitLambdef_nocond_body(Python3Parser.Lambdef_nocond_bodyContext ctx)
155155
@Override
156156
public T visitLambdef(Python3Parser.LambdefContext ctx) {
157157
argListCompilers.push(new ArgListCompiler<>(core));
158-
ctx.accept(argListCompilers.peek());
158+
if (ctx.varargslist() != null) {
159+
ctx.accept(argListCompilers.peek());
160+
}
159161
environment.beginScope(ctx, ScopeKind.Function);
160162
try {
161163
return super.visitLambdef(ctx);

0 commit comments

Comments
 (0)