Error message when two same states

This commit is contained in:
Denis Merigoux 2023-04-27 15:37:11 +02:00
parent 41d74bc673
commit 7788bf9e73
No known key found for this signature in database
GPG Key ID: EE99DCFA365C3EE3
3 changed files with 54 additions and 3 deletions

View File

@ -366,9 +366,29 @@ let process_data_decl
in
let states_idmap, states_list =
List.fold_right
(fun state_id (states_idmap, states_list) ->
(fun state_id
((states_idmap : StateName.t IdentName.Map.t), states_list) ->
let state_id_name = Marked.unmark state_id in
if IdentName.Map.mem state_id_name states_idmap then
Errors.raise_multispanned_error
[
( Some
(Format.asprintf "First instance of state %a:"
(Cli.format_with_style [ANSITerminal.yellow])
("\"" ^ state_id_name ^ "\"")),
Marked.get_mark state_id );
( Some
(Format.asprintf "Second instance of state %a:"
(Cli.format_with_style [ANSITerminal.yellow])
("\"" ^ state_id_name ^ "\"")),
Marked.get_mark
(IdentName.Map.find state_id_name states_idmap
|> StateName.get_info) );
]
"There are two states with the same name for the same variable: \
this is ambiguous. Please change the name of either states.";
let state_uid = StateName.fresh state_id in
( IdentName.Map.add (Marked.unmark state_id) state_uid states_idmap,
( IdentName.Map.add state_id_name state_uid states_idmap,
state_uid :: states_list ))
decl.scope_decl_context_item_states (IdentName.Map.empty, [])
in

View File

@ -43,7 +43,7 @@ $ catala Interpret -t -s HousingComputation
7 │ definition f of x equals (output of RentComputation).f of x
│ ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
[LOG] ≔ RentComputation.direct.output: { "f" = λ (param0: integer) → { "f" = λ (x: integer) → error_empty ⟨true ⊢ (λ (x1: integer) → error_empty ⟨true ⊢ x1 +! 1⟩) (x +! 1)⟩ }_RentComputation."f" param0 }_RentComputation
[LOG] ≔ RentComputation.direct.output: { "f" = <function>}_RentComputation
[LOG] ← RentComputation.direct
[LOG] → RentComputation.f
[LOG] ≔ RentComputation.f.input0: 1

View File

@ -0,0 +1,31 @@
## Test
```catala
declaration scope A:
output foo content integer
state bar
state bar
scope A:
definition foo state bar equals 2
```
```catala-test-inline
$ catala Typecheck
[ERROR] There are two states with the same name for the same variable: this is ambiguous. Please change the name of either states.
First instance of state "bar":
┌─⯈ tests/test_variable_state/bad/double_same_state.catala_en:6.11-6.14:
└─┐
6 │ state bar
│ ‾‾‾
└─ Test
Second instance of state "bar":
┌─⯈ tests/test_variable_state/bad/double_same_state.catala_en:7.11-7.14:
└─┐
7 │ state bar
│ ‾‾‾
└─ Test
#return code 255#
```