GDScript: Forbid enum values to shadow constants

- Don't allow constants to shadow parent members.
- Fix a spelling mistake.

Fix #13175
This commit is contained in:
George Marques 2018-09-10 11:06:03 -03:00
parent 6c70c4c358
commit e6a6ea65c7
No known key found for this signature in database
GPG Key ID: 046BD46A3201E43D

View File

@ -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