diff --git a/rflx/specification/parser.py b/rflx/specification/parser.py index 284f4cc46..44e859496 100644 --- a/rflx/specification/parser.py +++ b/rflx/specification/parser.py @@ -226,17 +226,22 @@ def create_state( package: ID, filename: Path, ) -> model.State: - location = node_location(state, filename) identifier = create_id(error, state.f_identifier, filename) assert isinstance(state.f_body, lang.StateBody) if state.f_identifier.text != state.f_body.f_end_identifier.text: error.extend( [ ErrorEntry( - "inconsistent state identifier: " - f"{state.f_identifier.text} /= {state.f_body.f_end_identifier.text}", + f'inconsistent state identifier "{state.f_body.f_end_identifier.text}"', Severity.ERROR, - location, + node_location(state.f_body.f_end_identifier, filename), + [ + Annotation( + f'previous identifier was "{identifier}"', + Severity.NOTE, + node_location(state.f_identifier, filename), + ), + ], ), ], ) @@ -274,10 +279,17 @@ def _check_state_machine_identifier( error.extend( [ ErrorEntry( - "inconsistent state machine identifier: " - f"{state_machine.f_identifier.text} /= {state_machine.f_end_identifier.text}", + "inconsistent state machine identifier" + f' "{state_machine.f_end_identifier.text}"', Severity.ERROR, - node_location(state_machine, filename), + node_location(state_machine.f_end_identifier, filename), + [ + Annotation( + f'previous identifier was "{state_machine.f_identifier.text}"', + Severity.NOTE, + node_location(state_machine.f_identifier, filename), + ), + ], ), ], ) diff --git a/tests/unit/specification/parser_test.py b/tests/unit/specification/parser_test.py index 741b7bca5..a966716a6 100644 --- a/tests/unit/specification/parser_test.py +++ b/tests/unit/specification/parser_test.py @@ -4769,7 +4769,10 @@ def test_state_error() -> None: goto B end C """ - error = ":2:8: error: inconsistent state identifier: A /= C.*" + error = ( + r':6:12: error: inconsistent state identifier "C"\n' + r':2:14: note: previous identifier was "A"' + ) with pytest.raises(RecordFluxError, match=rf"^{error}$"): parse_state(string) @@ -4853,7 +4856,8 @@ def test_parse_state_machine() -> None: end A; end Y """, - ":2:16: error: inconsistent state machine identifier: X /= Y.*", + r':10:20: error: inconsistent state machine identifier "Y"\n' + r':3:24: note: previous identifier was "X"', ), ( """