Skip to content

Commit

Permalink
Ensure Ada strings don't contain newlines
Browse files Browse the repository at this point in the history
Ref. #907
  • Loading branch information
senier committed Jul 7, 2022
1 parent a1d829d commit 6238613
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rflx/ada.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def precedence(self) -> Precedence:

class String(Aggregate):
def __init__(self, data: str) -> None:
data = data.replace('"', '""')
data = data.replace('"', '""').replace("\n", " ")
super().__init__(*[Number(ord(d)) for d in data])
self.data = data

Expand Down
15 changes: 15 additions & 0 deletions rflx/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -2787,7 +2787,9 @@ def _update_str(self) -> None:

def _check_type_subexpr(self) -> RecordFluxError:
error = RecordFluxError()

resulttype: rty.Type = rty.Any()

for _, expr in self.choices:
error += expr.check_type_instance(rty.Any)
resulttype = resulttype.common_type(expr.type_)
Expand Down Expand Up @@ -2815,6 +2817,19 @@ def _check_type_subexpr(self) -> RecordFluxError:

error += self.expr.check_type_instance(rty.Any)
error.propagate()

if not isinstance(self.expr.type_, (rty.AnyInteger, rty.Enumeration)):
error.extend(
[
(
f'invalid discrete choice type "{self.expr.type_}"',
Subsystem.MODEL,
Severity.ERROR,
self.expr.location,
),
]
)

self.type_ = resulttype

return error
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/expression_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2520,6 +2520,11 @@ def test_case_type() -> None:
r'"__BUILTINS__::Boolean"\n'
r'model: warning: conflicting with "1" which has type type universal integer \(1\)$',
)
assert_type_error(
Case(Opaque(Variable("X", type_=rty.Message("A"))), [([ID("V")], Number(1))]),
r'^model: error: invalid discrete choice type "sequence type "__INTERNAL__::Opaque" '
r'with element integer type "Byte" \(0 .. 255\)"$',
)


def test_case_simplified() -> None:
Expand Down

0 comments on commit 6238613

Please sign in to comment.