diff --git a/CHANGELOG.md b/CHANGELOG.md index 6009ae5cb..9b6f55ff9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/rflx/expr.py b/rflx/expr.py index 9d0cadb7a..b3ad6de2c 100644 --- a/rflx/expr.py +++ b/rflx/expr.py @@ -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 diff --git a/tests/unit/model/message_test.py b/tests/unit/model/message_test.py index 36b83c94a..3f9ab85ef 100644 --- a/tests/unit/model/message_test.py +++ b/tests/unit/model/message_test.py @@ -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( @@ -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), ]