Fix some error handling on scope calls

(and add suggestions)
This commit is contained in:
Louis Gesbert 2023-11-07 14:25:30 +01:00
parent d00cac09ad
commit dc3ffa0dcd
4 changed files with 15 additions and 8 deletions

View File

@ -293,11 +293,13 @@ let rec translate_expr (ctx : 'm ctx) (e : 'm Scopelang.Ast.expr) :
]
"Definition of input variable '%a' missing in this scope call"
ScopeVar.format var_name
| None, Some _ ->
Message.raise_multispanned_error
| None, Some e ->
Message.raise_multispanned_error_full
~suggestion:(List.map (fun v -> Mark.remove (ScopeVar.get_info v))
(ScopeVar.Map.keys sc_sig.scope_sig_in_fields))
[
None, pos;
( Some "Declaration of scope '%a'",
None, Expr.pos e;
( Some (fun ppf -> Format.fprintf ppf "Declaration of scope %a" ScopeName.format scope),
Mark.get (ScopeName.get_info scope) );
]
"Unknown input variable '%a' in scope call of '%a'"

View File

@ -446,6 +446,7 @@ let rec translate_expr
| Some (ScopeVar v) -> v
| Some (SubScope _) | None ->
Message.raise_multispanned_error
~suggestion:(Ident.Map.keys scope_def.var_idmap)
[
None, Mark.get fld_id;
( Some

View File

@ -29,5 +29,9 @@ Scope Toto declared here
└─┐
2 │ declaration scope Toto:
│ ‾‾‾‾
Maybe you wanted to write : "bar",
or "baz",
or "foo"
#return code 123#
```

View File

@ -11,7 +11,7 @@ scope Toto:
declaration scope Titi:
output fizz content Toto
scope Titi:
definition fizz equals output of Toto with {--bar: 1}
definition fizz equals output of Toto with {--bar: 1 }
```
```catala-test-inline
@ -19,10 +19,10 @@ $ catala dcalc -s Titi
[ERROR]
Definition of input variable 'baz' missing in this scope call
┌─⯈ tests/test_scope/bad/scope_call_missing.catala_en:14.26-14.56:
┌─⯈ tests/test_scope/bad/scope_call_missing.catala_en:14.26-14.57:
└──┐
14 │ definition fizz equals output of Toto with {--bar: 1}
│ ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
14 │ definition fizz equals output of Toto with {--bar: 1 }
│ ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
Declaration of the missing input variable
┌─⯈ tests/test_scope/bad/scope_call_missing.catala_en:4.16-4.19: