diff options
Diffstat (limited to 'modules')
3 files changed, 24 insertions, 8 deletions
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index a6b8537074..bbea6fe857 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -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())); } } diff --git a/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.gd b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.gd new file mode 100644 index 0000000000..4cbb464f59 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.gd @@ -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) diff --git a/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.out b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.out new file mode 100644 index 0000000000..7536c38490 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.out @@ -0,0 +1,5 @@ +GDTEST_OK +1 +2 +3 +4 |