Fixed all bugs

This commit is contained in:
Denis Merigoux 2022-01-05 15:57:18 +01:00
parent 82c09ee455
commit 909e539cdc
No known key found for this signature in database
GPG Key ID: EE99DCFA365C3EE3
14 changed files with 59 additions and 84 deletions

View File

@ -946,8 +946,8 @@ let process_def (precond : Scopelang.Ast.expr Pos.marked Bindlib.box option)
match scope_def_ctxt.default_exception_rulename with
(* This should have been caught previously by check_unlabeled_exception *)
| None | Some (Name_resolution.Ambiguous _) -> assert false
| Some (Name_resolution.Unique name) ->
(Desugared.Ast.RuleSet.singleton name, Pos.get_position def.Ast.definition_name))
| Some (Name_resolution.Unique (name, pos)) -> (Desugared.Ast.RuleSet.singleton name, pos)
)
| ExceptionToLabel label -> (
try
let label_id =
@ -1032,33 +1032,22 @@ let check_unlabeled_exception (scope : Scopelang.Ast.ScopeName.t) (ctxt : Name_r
(item : Ast.scope_use_item Pos.marked) : unit =
let scope_ctxt = Scopelang.Ast.ScopeMap.find scope ctxt.scopes in
match Pos.unmark item with
| Ast.Rule rule -> (
let def_key =
Name_resolution.get_def_key (Pos.unmark rule.rule_name) scope ctxt
(Pos.get_position rule.rule_name)
| Ast.Rule _ | Ast.Definition _ -> (
let def_key, exception_to =
match Pos.unmark item with
| Ast.Rule rule ->
( Name_resolution.get_def_key (Pos.unmark rule.rule_name) scope ctxt
(Pos.get_position rule.rule_name),
rule.rule_exception_to )
| Ast.Definition def ->
( Name_resolution.get_def_key (Pos.unmark def.definition_name) scope ctxt
(Pos.get_position def.definition_name),
def.definition_exception_to )
| _ -> assert false
(* should not happen *)
in
let scope_def_ctxt = Desugared.Ast.ScopeDefMap.find def_key scope_ctxt.scope_defs_contexts in
match rule.rule_exception_to with
| Ast.NotAnException | Ast.ExceptionToLabel _ -> ()
(* If this is an unlabeled exception, we check that it has a unique default definition *)
| Ast.UnlabeledException -> (
match scope_def_ctxt.default_exception_rulename with
| None ->
Errors.raise_spanned_error "This exception does not have a corresponding definition"
(Pos.get_position item)
| Some (Ambiguous pos) ->
Errors.raise_multispanned_error
"This exception can refer to several definitions. Try using labels to disambiguate"
([ (Some "Ambiguous exception", Pos.get_position item) ]
@ List.map (fun p -> (Some "Candidate definition", p)) pos)
| Some (Unique _) -> ()))
| Ast.Definition def -> (
let def_key =
Name_resolution.get_def_key (Pos.unmark def.definition_name) scope ctxt
(Pos.get_position def.definition_name)
in
let scope_def_ctxt = Desugared.Ast.ScopeDefMap.find def_key scope_ctxt.scope_defs_contexts in
match def.definition_exception_to with
match exception_to with
| Ast.NotAnException | Ast.ExceptionToLabel _ -> ()
(* If this is an unlabeled exception, we check that it has a unique default definition *)
| Ast.UnlabeledException -> (

View File

@ -23,7 +23,7 @@ type ident = string
type typ = Scopelang.Ast.typ
type unique_rulename = Ambiguous of Pos.t list | Unique of Desugared.Ast.RuleName.t
type unique_rulename = Ambiguous of Pos.t list | Unique of Desugared.Ast.RuleName.t Pos.marked
type scope_def_context = {
default_exception_rulename : unique_rulename option;
@ -542,11 +542,7 @@ let process_definition (ctxt : context) (s_name : Scopelang.Ast.ScopeName.t) (d
@
match old with
| Ambiguous old -> old
| Unique n ->
[
Pos.get_position
(Desugared.Ast.RuleName.get_info n);
]));
| Unique (_, pos) -> [ pos ]));
}
(* No definition has been set yet for this key *)
| None -> (
@ -564,7 +560,10 @@ let process_definition (ctxt : context) (s_name : Scopelang.Ast.ScopeName.t) (d
| None ->
{
def_key_ctx with
default_exception_rulename = Some (Unique d.definition_id);
default_exception_rulename =
Some
(Unique
(d.definition_id, Pos.get_position d.definition_name));
}))
in
Some def_key_ctx)

View File

@ -23,7 +23,7 @@ type ident = string
type typ = Scopelang.Ast.typ
type unique_rulename = Ambiguous of Pos.t list | Unique of Desugared.Ast.RuleName.t
type unique_rulename = Ambiguous of Pos.t list | Unique of Desugared.Ast.RuleName.t Pos.marked
type scope_def_context = {
default_exception_rulename : unique_rulename option;

View File

@ -1,15 +1,15 @@
[ERROR] There is a conflict between multiple exceptions for assigning the same variable.
[ERROR] There is a conflict between multiple validd consequences for assigning the same variable.
This justification is true:
This consequence has a valid justification:
--> test_default/bad/conflict.catala_en
|
9 | definition x under condition true consequence equals 0
| ^^^^
| ^
+ Article
This justification is true:
This consequence has a valid justification:
--> test_default/bad/conflict.catala_en
|
8 | definition x under condition true consequence equals 1
| ^^^^
| ^
+ Article

View File

@ -1,4 +1,4 @@
[ERROR] Unknown label for variable x: "base_y"
[ERROR] Unknown label for the scope variable x: "base_y"
--> test_exception/bad/dangling_exception.catala_en
|

View File

@ -1,17 +0,0 @@
[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
|
12 | label base_x
| ^^^^^^
+ Test
Existing rule with same label:
--> test_exception/bad/duplicate_labels.catala_en
|
9 | label base_x
| ^^^^^^^^^^^
10 | definition x under condition y >= 0 consequence equals -1
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+

View File

@ -14,8 +14,8 @@ Cyclic exception for definition of variable "x", declared here:
Used here in the definition of another cyclic exception for defining "x":
--> test_exception/bad/exceptions_cycle.catala_en
|
17 | exception exception_x
| ^^^^^^^^^^^
18 | definition x equals 2
| ^
+ Test
Cyclic exception for definition of variable "x", declared here:
@ -32,8 +32,8 @@ Cyclic exception for definition of variable "x", declared here:
Used here in the definition of another cyclic exception for defining "x":
--> test_exception/bad/exceptions_cycle.catala_en
|
13 | exception base_x
| ^^^^^^
14 | definition x equals 1
| ^
+ Test
Cyclic exception for definition of variable "x", declared here:
@ -50,6 +50,6 @@ Cyclic exception for definition of variable "x", declared here:
Used here in the definition of another cyclic exception for defining "x":
--> test_exception/bad/exceptions_cycle.catala_en
|
9 | exception exception_exception_x
| ^^^^^^^^^^^^^^^^^^^^^
10 | definition x equals 0
| ^
+ Test

View File

@ -2,6 +2,6 @@
--> test_exception/bad/self_exception.catala_en
|
9 | exception base_y
| ^^^^^^
10 | definition y equals 0
| ^
+ Test

View File

@ -1,13 +1,13 @@
[ERROR] There is a conflict between multiple exceptions for assigning the same variable.
[ERROR] There is a conflict between multiple validd consequences for assigning the same variable.
This justification is true:
This consequence has a valid justification:
--> test_exception/bad/two_exceptions.catala_en
|
15 | definition x equals 2
| ^
+ Test
This justification is true:
This consequence has a valid justification:
--> test_exception/bad/two_exceptions.catala_en
|
12 | definition x equals 1

View File

@ -42,6 +42,6 @@ If the person is disabled, the benefit is equal to $2000.
```catala
scope Benefit:
exception benefits_base_case
definition benefit under condition person.is_disabled consequence equals $2000
definition benefit under condition person.disabled consequence equals $2000
```

View File

@ -0,0 +1,3 @@
[RESULT] Computation successful! Results:
[RESULT] x = 0
[RESULT] y = 0

View File

@ -1,2 +1,3 @@
[RESULT] Computation successful! Results:
[RESULT] benefit = $2000
[RESULT] benefit = $2000.00
[RESULT] person = Person {"age": 26, "disabled": true}

View File

@ -1,15 +1,15 @@
[ERROR] There is a conflict between multiple exceptions for assigning the same variable.
[ERROR] There is a conflict between multiple validd consequences for assigning the same variable.
This justification is true:
This consequence has a valid justification:
--> test_func/bad/bad_func.catala_en
|
15 | definition f of x under condition not b consequence equals x * x
| ^^^^^
+ Article
This justification is true:
This consequence has a valid justification:
--> test_func/bad/bad_func.catala_en
|
14 | definition f of x under condition (x >= x) consequence equals x + x
| ^^^^^^
| ^^^^^
+ Article