From 0a28b4cd94540e1b99ccd79a70bd37170e1cb614 Mon Sep 17 00:00:00 2001 From: George Marques Date: Mon, 23 May 2022 12:25:03 -0300 Subject: GDScript: Do not allow standalone lambdas They cannot be accessed in this case, so an error is shown to avoid misleading the uses, especially in case of named lambdas. --- modules/gdscript/gdscript_parser.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'modules/gdscript/gdscript_parser.cpp') diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 96d1f68f60..8327da79e2 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -1624,6 +1624,10 @@ GDScriptParser::Node *GDScriptParser::parse_statement() { case Node::AWAIT: // Fine. break; + case Node::LAMBDA: + // Standalone lambdas can't be used, so make this an error. + push_error("Standalone lambdas cannot be accessed. Consider assigning it to a variable.", expression); + break; default: push_warning(expression, GDScriptWarning::STANDALONE_EXPRESSION); } -- cgit v1.2.3 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gdscript/gdscript_parser.cpp') 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. -- cgit v1.2.3 From 1b76a9d70515cc98d9772c72daadbf2634aa788f Mon Sep 17 00:00:00 2001 From: George Marques Date: Mon, 23 May 2022 21:38:31 -0300 Subject: GDScript: Fix lambda captures in default argument values --- modules/gdscript/gdscript_parser.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'modules/gdscript/gdscript_parser.cpp') diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index f23cddcbda..b93fff3914 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -2926,6 +2926,9 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_lambda(ExpressionNode *p_p current_function = function; SuiteNode *body = alloc_node(); + body->parent_function = current_function; + body->parent_block = current_suite; + SuiteNode *previous_suite = current_suite; current_suite = body; -- cgit v1.2.3