GDScript: Fix false name conflicts for unnamed enums

This commit is contained in:
Dmitrii Maganov 2022-12-29 21:48:04 +02:00
parent a754930918
commit 056066ee95
3 changed files with 24 additions and 8 deletions

View file

@ -1319,14 +1319,8 @@ GDScriptParser::EnumNode *GDScriptParser::parse_enum() {
if (elements.has(item.identifier->name)) {
push_error(vformat(R"(Name "%s" was already in this enum (at line %d).)", item.identifier->name, elements[item.identifier->name]), item.identifier);
} else if (!named) {
// TODO: Abstract this recursive member check.
ClassNode *parent = current_class;
while (parent != nullptr) {
if (parent->members_indices.has(item.identifier->name)) {
push_error(vformat(R"(Name "%s" is already used as a class %s.)", item.identifier->name, parent->get_member(item.identifier->name).get_type_name()));
break;
}
parent = parent->outer;
if (current_class->members_indices.has(item.identifier->name)) {
push_error(vformat(R"(Name "%s" is already used as a class %s.)", item.identifier->name, current_class->get_member(item.identifier->name).get_type_name()));
}
}

View file

@ -0,0 +1,17 @@
class A:
enum { X = 1 }
class B:
enum { X = 2 }
class C:
const X = 3
class D:
enum { X = 4 }
func test():
print(A.X)
print(A.B.X)
print(C.X)
print(C.D.X)

View file

@ -0,0 +1,5 @@
GDTEST_OK
1
2
3
4