Skip to content

Commit

Permalink
Add check for name conflicts between field names and enum literals
Browse files Browse the repository at this point in the history
Ref. #309
  • Loading branch information
treiher committed Jul 23, 2020
1 parent 70a37e7 commit 5406f94
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions rflx/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,28 @@ def __verify(self) -> None:
]
)

name_conflicts = [
(f, l)
for f in type_fields
for l in qualified_literals(self.types, self.package)
if f.identifier == l
]

if name_conflicts:
conflicting_field, conflicting_literal = name_conflicts.pop(0)
self.error.append(
f'name conflict for field "{conflicting_field.name}" in "{self.identifier}"',
Subsystem.MODEL,
Severity.ERROR,
conflicting_field.identifier.location,
)
self.error.append(
"conflicting enumeration literal",
Subsystem.MODEL,
Severity.INFO,
conflicting_literal.location,
)

self.error.propagate()

for f in structure_fields:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,29 @@ def test_message_ambiguous_first_field() -> None:
)


def test_message_name_conflict_field_enum() -> None:
t = Enumeration(
"P.T",
[(ID("X", Location((3, 27))), Number(1)), (ID("Y", Location((3, 32))), Number(2))],
Number(8),
False,
)

structure = [
Link(INITIAL, Field("X")),
Link(Field("X"), FINAL),
]

types = {Field(ID("X", Location((5, 6)))): t}

assert_message_model_error(
structure,
types,
'^<stdin>:5:6: model: error: name conflict for field "X" in "P.M"\n'
"<stdin>:3:27: model: info: conflicting enumeration literal",
)


def test_message_duplicate_link() -> None:
t = ModularInteger("P.T", Number(2))
x = Field(ID("X", location=Location((1, 5))))
Expand Down

0 comments on commit 5406f94

Please sign in to comment.