mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-08 07:51:43 +03:00
Fixed all bugs
This commit is contained in:
parent
82c09ee455
commit
909e539cdc
@ -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 -> (
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
||||
|
@ -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
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
+
|
@ -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:
|
||||
@ -48,8 +48,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
|
||||
|
|
||||
9 | exception exception_exception_x
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
+ Test
|
||||
--> test_exception/bad/exceptions_cycle.catala_en
|
||||
|
|
||||
10 | definition x equals 0
|
||||
| ^
|
||||
+ Test
|
||||
|
@ -1,7 +1,7 @@
|
||||
[ERROR] Cannot define rule as an exception to itself
|
||||
|
||||
--> test_exception/bad/self_exception.catala_en
|
||||
|
|
||||
9 | exception base_y
|
||||
| ^^^^^^
|
||||
+ Test
|
||||
--> test_exception/bad/self_exception.catala_en
|
||||
|
|
||||
10 | definition y equals 0
|
||||
| ^
|
||||
+ Test
|
||||
|
@ -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_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
|
||||
| ^
|
||||
| ^
|
||||
+ Test
|
||||
|
@ -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
|
||||
```
|
||||
|
||||
|
@ -0,0 +1,3 @@
|
||||
[RESULT] Computation successful! Results:
|
||||
[RESULT] x = 0
|
||||
[RESULT] y = 0
|
@ -1,2 +1,3 @@
|
||||
[RESULT] Computation successful! Results:
|
||||
[RESULT] benefit = $2000
|
||||
[RESULT] benefit = $2000.00
|
||||
[RESULT] person = Person {"age": 26, "disabled": true}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user