Merge pull request #70713 from vonagam/fix-unnamed-enum-outer-conflicts

This commit is contained in:
George Marques 2023-01-12 11:22:01 -03:00 committed by GitHub
commit 7319fa6082
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 8 deletions

View file

@ -1321,14 +1321,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