You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-22 15:06:45 +00:00
GDScript: Forbid invalid identifiers in match bindings
Also forbid shadowing a variable from an upper scope.
This commit is contained in:
@@ -2024,12 +2024,20 @@ GDScriptParser::PatternNode *GDScriptParser::_parse_pattern(bool p_static) {
|
|||||||
// bind
|
// bind
|
||||||
case GDScriptTokenizer::TK_PR_VAR: {
|
case GDScriptTokenizer::TK_PR_VAR: {
|
||||||
tokenizer->advance();
|
tokenizer->advance();
|
||||||
|
if (!tokenizer->is_token_literal()) {
|
||||||
|
_set_error("Expected identifier for binding variable name.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
pattern->pt_type = GDScriptParser::PatternNode::PT_BIND;
|
pattern->pt_type = GDScriptParser::PatternNode::PT_BIND;
|
||||||
pattern->bind = tokenizer->get_token_identifier();
|
pattern->bind = tokenizer->get_token_identifier();
|
||||||
// Check if binding is already used
|
// Check if variable name is already used
|
||||||
if (current_block->variables.has(pattern->bind)) {
|
BlockNode *bl = current_block;
|
||||||
_set_error("Binding name of '" + pattern->bind.operator String() + "' was already used in the pattern.");
|
while (bl) {
|
||||||
return NULL;
|
if (bl->variables.has(pattern->bind)) {
|
||||||
|
_set_error("Binding name of '" + pattern->bind.operator String() + "' is already declared in this scope.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
bl = bl->parent_block;
|
||||||
}
|
}
|
||||||
// Create local variable for proper identifier detection later
|
// Create local variable for proper identifier detection later
|
||||||
LocalVarNode *lv = alloc_node<LocalVarNode>();
|
LocalVarNode *lv = alloc_node<LocalVarNode>();
|
||||||
|
|||||||
Reference in New Issue
Block a user