mirror of
https://github.com/godotengine/godot.git
synced 2024-12-09 10:09:20 +08:00
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.
This commit is contained in:
parent
a76db34592
commit
0a28b4cd94
@ -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);
|
||||
}
|
||||
|
@ -0,0 +1,3 @@
|
||||
func test():
|
||||
func standalone():
|
||||
print("can't be accessed")
|
@ -0,0 +1,2 @@
|
||||
GDTEST_PARSER_ERROR
|
||||
Standalone lambdas cannot be accessed. Consider assigning it to a variable.
|
Loading…
Reference in New Issue
Block a user