diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-01-14 17:07:08 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-14 17:07:08 -0300 |
commit | 7924f08a6afc56bd2d3a116c91ad6383c4579051 (patch) | |
tree | 317ca52cc0988c52304ef9c38bdc66a758ca98ab /modules/gdscript | |
parent | 94609305a021305db2a02c63890f9e23c37d0dd8 (diff) | |
parent | 9e86b2714faa295df6c0dd8be207862ef0c67c0e (diff) |
Merge pull request #4918 from jjay/f/error_on_redefine
Redefine var results in an error
Diffstat (limited to 'modules/gdscript')
-rw-r--r-- | modules/gdscript/gd_parser.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index bd0704fff9..c783fac429 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -1762,6 +1762,24 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { } StringName n = tokenizer->get_token_identifier(); tokenizer->advance(); + if (current_function){ + for (int i=0;i<current_function->arguments.size();i++){ + if (n == current_function->arguments[i]){ + _set_error("Variable '"+String(n)+"' already defined in the scope (at line: "+itos(current_function->line)+")."); + return; + } + } + } + BlockNode *check_block = p_block; + while (check_block){ + for (int i=0;i<check_block->variables.size();i++){ + if (n == check_block->variables[i]){ + _set_error("Variable '"+String(n)+"' already defined in the scope (at line: "+itos(check_block->variable_lines[i])+")."); + return; + } + } + check_block = check_block->parent_block; + } p_block->variables.push_back(n); //line? p_block->variable_lines.push_back(tokenizer->get_token_line()); @@ -2079,7 +2097,14 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { } current_block=cf_for->body; + + // this is for checking variable for redefining + // inside this _parse_block + cf_for->body->variables.push_back(id->name); + cf_for->body->variable_lines.push_back(id->line); _parse_block(cf_for->body,p_static); + cf_for->body->variables.remove(0); + cf_for->body->variable_lines.remove(0); current_block=p_block; if (error_set) |