diff --git a/compiler/surface/name_resolution.ml b/compiler/surface/name_resolution.ml index a3383e36..b2b9f749 100644 --- a/compiler/surface/name_resolution.ml +++ b/compiler/surface/name_resolution.ml @@ -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:", diff --git a/tests/test_exception/bad/output/duplicate_labels.catala_en.A.out b/tests/test_exception/bad/output/duplicate_labels.catala_en.A.out index 923ca506..ac8fed5f 100644 --- a/tests/test_exception/bad/output/duplicate_labels.catala_en.A.out +++ b/tests/test_exception/bad/output/duplicate_labels.catala_en.A.out @@ -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 diff --git a/tests/test_exception/bad/output/same_label_two_variables.catala_en.A.out b/tests/test_exception/bad/output/same_label_two_variables.catala_en.A.out new file mode 100644 index 00000000..16412201 --- /dev/null +++ b/tests/test_exception/bad/output/same_label_two_variables.catala_en.A.out @@ -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 + | ^^^^^^^^^^^^^^^^^^^^^^^ + + diff --git a/tests/test_exception/bad/same_label_two_variables.catala_en b/tests/test_exception/bad/same_label_two_variables.catala_en new file mode 100644 index 00000000..f1b2c227 --- /dev/null +++ b/tests/test_exception/bad/same_label_two_variables.catala_en @@ -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 +```