Skip to content

Commit

Permalink
Fix consequential errors caused by undefined variables
Browse files Browse the repository at this point in the history
Ref. eng/recordflux/RecordFlux!1666
  • Loading branch information
treiher authored and andrestt committed Sep 27, 2024
1 parent 707ba0c commit ac3b004
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Rejection of invalid parameter types and return types in function declarations (eng/recordflux/RecordFlux#977)
- Consequential errors caused by undefined variables in binary expressions (eng/recordflux/RecordFlux#1672)

## [0.24.0] - 2024-09-12

Expand Down
3 changes: 2 additions & 1 deletion rflx/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,8 @@ def _check_type_subexpr(self) -> RecordFluxError:
for e in [self.left, self.right]:
error.extend(e.check_type_instance(ty.AnyInteger).entries)

self.type_ = ty.common_type([self.left.type_, self.right.type_])
common_type = ty.common_type([self.left.type_, self.right.type_])
self.type_ = common_type if common_type != ty.UNDEFINED else ty.BASE_INTEGER

return error

Expand Down
23 changes: 17 additions & 6 deletions tests/unit/model/message_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,22 @@ def test_reference_to_optional_field_1() -> None:
)


def test_reference_to_optional_field_2() -> None:
@pytest.mark.parametrize(
("size_expression"),
[
Mul(
Variable("Opt", location=Location((10, 30))),
Number(8),
location=Location((10, 20)),
),
Sub(
Variable("Opt", location=Location((10, 30))),
Number(8),
location=Location((10, 20)),
),
],
)
def test_reference_to_optional_field_2(size_expression: Expr) -> None:
structure = [
Link(INITIAL, Field(ID("Flag", location=Location((1, 1))))),
Link(
Expand All @@ -1087,11 +1102,7 @@ def test_reference_to_optional_field_2() -> None:
Link(
Field(ID("Any", location=Location((5, 5)))),
Field(ID("Data", location=Location((5, 6)))),
size=Mul(
Variable("Opt", location=Location((10, 30))),
Number(8),
location=Location((10, 20)),
),
size=size_expression,
),
Link(Field(ID("Data", location=Location((7, 7)))), FINAL),
]
Expand Down

0 comments on commit ac3b004

Please sign in to comment.