From 969f1980d29cfc48c45a1bebdc98935b641dda50 Mon Sep 17 00:00:00 2001 From: George Marques Date: Mon, 23 May 2022 21:13:25 -0300 Subject: GDScript: Fix `if` after lambda being seen as ternary --- modules/gdscript/gdscript_parser.cpp | 2 +- modules/gdscript/tests/scripts/parser/features/if_after_lambda.gd | 7 +++++++ modules/gdscript/tests/scripts/parser/features/if_after_lambda.out | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 modules/gdscript/tests/scripts/parser/features/if_after_lambda.gd create mode 100644 modules/gdscript/tests/scripts/parser/features/if_after_lambda.out (limited to 'modules/gdscript') diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 8327da79e2..f23cddcbda 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -2103,7 +2103,7 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_precedence(Precedence p_pr ExpressionNode *previous_operand = (this->*prefix_rule)(nullptr, p_can_assign); while (p_precedence <= get_rule(current.type)->precedence) { - if (previous_operand == nullptr || (p_stop_on_assign && current.type == GDScriptTokenizer::Token::EQUAL)) { + if (previous_operand == nullptr || (p_stop_on_assign && current.type == GDScriptTokenizer::Token::EQUAL) || (previous_operand->type == Node::LAMBDA && lambda_ended)) { return previous_operand; } // Also switch multiline mode on here for infix operators. diff --git a/modules/gdscript/tests/scripts/parser/features/if_after_lambda.gd b/modules/gdscript/tests/scripts/parser/features/if_after_lambda.gd new file mode 100644 index 0000000000..f5e26ab1ab --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/if_after_lambda.gd @@ -0,0 +1,7 @@ +# https://github.com/godotengine/godot/issues/61231 + +func test(): + var my_lambda = func(): + print("hello") + if 0 == 0: + my_lambda.call() diff --git a/modules/gdscript/tests/scripts/parser/features/if_after_lambda.out b/modules/gdscript/tests/scripts/parser/features/if_after_lambda.out new file mode 100644 index 0000000000..58774d2d3f --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/if_after_lambda.out @@ -0,0 +1,2 @@ +GDTEST_OK +hello -- cgit v1.2.3