Skip to content

Commit 41eef20

Browse files
committed
fix duplicated enum scope
1 parent 8101fc7 commit 41eef20

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

scripts/cxx-api/parser/builders.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,17 @@ def create_enum_scope(snapshot: Snapshot, enum_def: compound.EnumdefType) -> Non
463463
Create an enum scope in the snapshot.
464464
"""
465465
scope = snapshot.create_enum(enum_def.qualifiedname)
466-
scope.kind.type = resolve_linked_text_name(enum_def.get_type())[0]
467-
scope.location = enum_def.location.file
466+
if scope.kind.type is None:
467+
scope.kind.type = resolve_linked_text_name(enum_def.get_type())[0]
468+
if scope.location is None:
469+
scope.location = enum_def.location.file
470+
471+
existing_value_names = {member.name for member in scope.get_members()}
468472

469473
for enum_value_def in enum_def.enumvalue:
470474
value_name = enum_value_def.get_name()
475+
if value_name in existing_value_names:
476+
continue
471477
value_value = None
472478

473479
if enum_value_def.initializer is not None:
@@ -479,6 +485,7 @@ def create_enum_scope(snapshot: Snapshot, enum_def: compound.EnumdefType) -> Non
479485
value_value,
480486
),
481487
)
488+
existing_value_names.add(value_name)
482489

483490

484491
def _is_category_member(member_def: compound.MemberdefType) -> bool:

scripts/cxx-api/parser/snapshot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def create_enum(self, qualified_name: str) -> Scope[EnumScopeKind]:
177177
scope = current_scope.inner_scopes[enum_name]
178178
if scope.kind.name == "temporary":
179179
scope.kind = EnumScopeKind()
180+
elif scope.kind.name == "enum":
181+
return scope
180182
else:
181183
raise RuntimeError(
182184
f"Identifier {enum_name} already exists in scope {current_scope.name}"

0 commit comments

Comments
 (0)