Fix OCaml backend bug regarding exception source positions (#689)

This commit is contained in:
vbot 2024-09-17 11:18:16 +02:00 committed by GitHub
commit 7ccedafa13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 57 additions and 1 deletions

View File

@ -400,11 +400,14 @@ let rec format_expr (ctx : decl_ctx) (fmt : Format.formatter) (e : 'm expr) :
| Div_int_int | Div_rat_rat | Div_mon_mon | Div_mon_rat | Div_dur_dur ->
Format.fprintf ppf "%a@ " format_pos (Expr.pos (List.nth args 1))
| HandleExceptions ->
let excs =
match args with [(EArray ex, _)] -> ex | _ -> assert false
in
Format.fprintf ppf "[|@[<hov>%a@]|]@ "
(Format.pp_print_list
~pp_sep:(fun ppf () -> Format.fprintf ppf ";@ ")
format_pos)
(List.map Expr.pos args)
(List.map Expr.pos excs)
| _ -> ())
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt "@ ")

View File

@ -0,0 +1,22 @@
> Module Bool
```catala-metadata
declaration scope A:
input x content integer
input add_meaning_of_life content boolean
output out content integer
```
```catala
scope A:
definition out equals x
definition out under condition add_meaning_of_life consequence equals x + 42
```
```catala-test-inline
$ catala typecheck
┌─[RESULT]─
│ Typechecking successful!
└─
```

View File

@ -0,0 +1,31 @@
> Using Bool
```catala
declaration scope A_test:
output aout scope Bool.A
scope A_test:
definition aout.x equals 22
definition aout.add_meaning_of_life equals true
```
```catala-test-inline
$ catala interpret -s A_test
┌─[ERROR]─
│ During evaluation: conflict between multiple valid consequences for
│ assigning the same variable.
├─➤ tests/modules/bool.catala_en:12.25-12.26:
│ │
│ 12 │ definition out equals x
│ │ ‾
├─➤ tests/modules/bool.catala_en:13.73-13.79:
│ │
│ 13 │ definition out under condition add_meaning_of_life consequence equals x + 42
│ │ ‾‾‾‾‾‾
└─
#return code 123#
```