Better error message

This commit is contained in:
Denis Merigoux 2021-11-28 13:16:21 +01:00
parent d1b75b047b
commit 4137641c8c
No known key found for this signature in database
GPG Key ID: EE99DCFA365C3EE3
4 changed files with 41 additions and 3 deletions

View File

@ -28,6 +28,7 @@ type unique_rulename = Ambiguous of Pos.t list | Unique of Desugared.Ast.RuleNam
type scope_context = {
var_idmap : Scopelang.Ast.ScopeVar.t Desugared.Ast.IdentMap.t; (** Scope variables *)
label_idmap : Desugared.Ast.RuleName.t Desugared.Ast.IdentMap.t;
(** Set of rules attached to a label *)
default_rulemap : unique_rulename Desugared.Ast.ScopeDefMap.t;
(** What is the default rule to refer to for unnamed exceptions, if any *)
sub_scopes_idmap : Scopelang.Ast.SubScopeName.t Desugared.Ast.IdentMap.t;
@ -460,8 +461,8 @@ let process_definition (ctxt : context) (s_name : Scopelang.Ast.ScopeName.t) (d
match Desugared.Ast.IdentMap.find_opt (Pos.unmark label) s_ctxt.label_idmap with
| Some existing_label ->
Errors.raise_multispanned_error
"This label has already been given to a rule defining this variable, \
please pick a new one."
"This label has already been given to another rule, please pick a new \
one since labels should be unique."
[
(Some "Duplicate label:", Pos.get_position label);
( Some "Existing rule with same label:",

View File

@ -1,4 +1,4 @@
[ERROR] This label has already been given to a rule defining this variable, please pick a new one.
[ERROR] This label has already been given to another rule, please pick a new one since labels should be unique.
Duplicate label:
--> test_exception/bad/duplicate_labels.catala_en

View File

@ -0,0 +1,17 @@
[ERROR] This label has already been given to another rule, please pick a new one since labels should be unique.
Duplicate label:
--> test_exception/bad/same_label_two_variables.catala_en
|
13 | label base
| ^^^^
+ Test
Existing rule with same label:
--> test_exception/bad/same_label_two_variables.catala_en
|
10 | label base
| ^^^^^^^^^
11 | definition x equals -1
| ^^^^^^^^^^^^^^^^^^^^^^^
+

View File

@ -0,0 +1,20 @@
## Test
```catala
declaration scope A:
context x content integer
context y content integer
context z content integer
scope A:
label base
definition x equals -1
label base
definition y equals 1
exception base
definition x under condition z = 0 consequence equals 0
definition z equals 0
```