Skip to content

Commit

Permalink
Fix detection of undefined enum literals in refinement conditions
Browse files Browse the repository at this point in the history
Ref. #530
  • Loading branch information
treiher committed Jan 11, 2021
1 parent 76e3c62 commit 873193c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
8 changes: 1 addition & 7 deletions rflx/model/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1565,13 +1565,7 @@ def __init__(
)

for variable in condition.variables():
literals = [
l
for e in pdu.types.values()
if isinstance(e, mty.Enumeration)
for k in e.literals.keys()
for l in [e.package * k, k]
]
literals = mty.qualified_enum_literals(pdu.types.values(), self.package)
if Field(str(variable.name)) not in pdu.fields and variable.identifier not in literals:
self.error.append(
f'unknown field or literal "{variable.identifier}" in refinement'
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/model/message_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3117,3 +3117,35 @@ def test_refinement_invalid_condition() -> None:
r' of "P::M"'
r"$",
)


def test_refinement_invalid_condition_unqualified_literal() -> None:
e = Enumeration(
"P2::E",
[("E1", Number(1)), ("E2", Number(2)), ("E3", Number(3))],
Number(8),
False,
)

x = Field("X")
y = Field("Y")

message = Message(
"P::M",
[Link(INITIAL, x), Link(x, y, size=Number(8)), Link(y, FINAL)],
{x: e, y: OPAQUE},
)

assert_type_error(
Refinement(
"P",
message,
y,
message,
Equal(Variable("X"), Variable("E1", location=Location((10, 20)))),
),
r"^"
r'<stdin>:10:20: model: error: unknown field or literal "E1" in refinement condition'
r' of "P::M"'
r"$",
)

0 comments on commit 873193c

Please sign in to comment.