diff options
author | George Marques <george@gmarqu.es> | 2018-09-10 11:06:03 -0300 |
---|---|---|
committer | George Marques <george@gmarqu.es> | 2018-09-19 11:17:46 -0300 |
commit | e6a6ea65c7311175603a698b4051b90b2a112161 (patch) | |
tree | 18c534562d0fabf6fb32fc907264e773abe464a4 /modules | |
parent | 6c70c4c3587d8dccb9603231a01a6a17b1748808 (diff) |
GDScript: Forbid enum values to shadow constants
- Don't allow constants to shadow parent members.
- Fix a spelling mistake.
Fix #13175
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index aa1735522b..3dd335c45f 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -4863,6 +4863,20 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { StringName const_id = tokenizer->get_token_literal(); + if (current_class->constant_expressions.has(const_id)) { + _set_error("A constant named '" + String(const_id) + "' already exists in this class (at line: " + + itos(current_class->constant_expressions[const_id].expression->line) + ")."); + return; + } + + for (int i = 0; i < current_class->variables.size(); i++) { + if (current_class->variables[i].identifier == const_id) { + _set_error("A variable named '" + String(const_id) + "' already exists in this class (at line: " + + itos(current_class->variables[i].line) + ")."); + return; + } + } + tokenizer->advance(); if (tokenizer->get_token() == GDScriptTokenizer::TK_OP_ASSIGN) { @@ -7216,6 +7230,12 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) { expr.is_constant = true; c.type = expr; c.expression->set_datatype(expr); + + DataType tmp; + if (_get_member_type(p_class->base_type, E->key(), tmp)) { + _set_error("Member '" + String(E->key()) + "' already exists in parent class.", c.expression->line); + return; + } } // Function declarations |