You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-13 13:31:48 +00:00
GDScript: Fix parsing unexpected break/continue in lambda
This commit is contained in:
@@ -3138,6 +3138,14 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_lambda(ExpressionNode *p_p
|
|||||||
bool previous_in_lambda = in_lambda;
|
bool previous_in_lambda = in_lambda;
|
||||||
in_lambda = true;
|
in_lambda = true;
|
||||||
|
|
||||||
|
// Save break/continue state.
|
||||||
|
bool could_break = can_break;
|
||||||
|
bool could_continue = can_continue;
|
||||||
|
|
||||||
|
// Disallow break/continue.
|
||||||
|
can_break = false;
|
||||||
|
can_continue = false;
|
||||||
|
|
||||||
function->body = parse_suite("lambda declaration", body, true);
|
function->body = parse_suite("lambda declaration", body, true);
|
||||||
complete_extents(function);
|
complete_extents(function);
|
||||||
complete_extents(lambda);
|
complete_extents(lambda);
|
||||||
@@ -3155,6 +3163,11 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_lambda(ExpressionNode *p_p
|
|||||||
current_function = previous_function;
|
current_function = previous_function;
|
||||||
in_lambda = previous_in_lambda;
|
in_lambda = previous_in_lambda;
|
||||||
lambda->function = function;
|
lambda->function = function;
|
||||||
|
|
||||||
|
// Reset break/continue state.
|
||||||
|
can_break = could_break;
|
||||||
|
can_continue = could_continue;
|
||||||
|
|
||||||
return lambda;
|
return lambda;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
func test():
|
||||||
|
for index in range(0, 1):
|
||||||
|
var lambda := func():
|
||||||
|
continue
|
||||||
|
print('not ok')
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
GDTEST_PARSER_ERROR
|
||||||
|
Cannot use "continue" outside of a loop.
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
func test():
|
||||||
|
var i_string := ''
|
||||||
|
for i in 3:
|
||||||
|
if i == 1: continue
|
||||||
|
var lambda := func():
|
||||||
|
var j_string := ''
|
||||||
|
for j in 3:
|
||||||
|
if j == 1: continue
|
||||||
|
j_string += str(j)
|
||||||
|
return j_string
|
||||||
|
i_string += lambda.call()
|
||||||
|
assert(i_string == '0202')
|
||||||
|
print('ok')
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
GDTEST_OK
|
||||||
|
ok
|
||||||
Reference in New Issue
Block a user