mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-08 07:51:43 +03:00
Fixed a bug [skip ci]
This commit is contained in:
parent
3752328671
commit
82c09ee455
@ -28,20 +28,6 @@ type rule_tree =
|
||||
rules *)
|
||||
let def_map_to_tree (def_info : Ast.ScopeDef.t) (def : Ast.rule Ast.RuleMap.t) : rule_tree list =
|
||||
let exc_graph = Dependency.build_exceptions_graph def def_info in
|
||||
Cli.debug_print
|
||||
(Format.asprintf "For definition %a, the exception vertices are: %a" Ast.ScopeDef.format_t
|
||||
def_info
|
||||
(Format.pp_print_list
|
||||
~pp_sep:(fun fmt () -> Format.fprintf fmt "; ")
|
||||
(fun fmt ruleset ->
|
||||
Format.fprintf fmt "[%a]"
|
||||
(Format.pp_print_list
|
||||
~pp_sep:(fun fmt () -> Format.fprintf fmt "; ")
|
||||
(fun fmt (rule : Ast.RuleName.t) ->
|
||||
Format.fprintf fmt "%s"
|
||||
(Pos.to_string_short (Pos.get_position (Ast.RuleName.get_info rule)))))
|
||||
(List.of_seq (Ast.RuleSet.to_seq ruleset))))
|
||||
(Dependency.ExceptionsDependencies.fold_vertex (fun v acc -> v :: acc) exc_graph []));
|
||||
Dependency.check_for_exception_cycle exc_graph;
|
||||
(* we start by the base cases: they are the vertices which have no successors *)
|
||||
let base_cases =
|
||||
|
@ -928,15 +928,15 @@ let process_def (precond : Scopelang.Ast.expr Pos.marked Bindlib.box option)
|
||||
in
|
||||
let scope_updated =
|
||||
let scope_def =
|
||||
match Desugared.Ast.ScopeDefMap.find_opt def_key scope.scope_defs with
|
||||
| Some def -> def
|
||||
| None ->
|
||||
{
|
||||
scope_def_rules = Desugared.Ast.RuleMap.empty;
|
||||
scope_def_typ = Name_resolution.get_def_typ ctxt def_key;
|
||||
scope_def_is_condition = Name_resolution.is_def_cond ctxt def_key;
|
||||
scope_def_label_groups = Name_resolution.label_groups ctxt scope_uid def_key;
|
||||
}
|
||||
{
|
||||
Desugared.Ast.scope_def_rules =
|
||||
(match Desugared.Ast.ScopeDefMap.find_opt def_key scope.scope_defs with
|
||||
| Some def -> def.scope_def_rules
|
||||
| None -> Desugared.Ast.RuleMap.empty);
|
||||
scope_def_typ = Name_resolution.get_def_typ ctxt def_key;
|
||||
scope_def_is_condition = Name_resolution.is_def_cond ctxt def_key;
|
||||
scope_def_label_groups = Name_resolution.label_groups ctxt scope_uid def_key;
|
||||
}
|
||||
in
|
||||
let rule_name = def.definition_id in
|
||||
let parent_rules =
|
||||
@ -950,9 +950,10 @@ let process_def (precond : Scopelang.Ast.expr Pos.marked Bindlib.box option)
|
||||
(Desugared.Ast.RuleSet.singleton name, Pos.get_position def.Ast.definition_name))
|
||||
| ExceptionToLabel label -> (
|
||||
try
|
||||
( Desugared.Ast.LabelMap.find
|
||||
(Desugared.Ast.IdentMap.find (Pos.unmark label) scope_def_ctxt.label_idmap)
|
||||
scope_def.scope_def_label_groups,
|
||||
let label_id =
|
||||
Desugared.Ast.IdentMap.find (Pos.unmark label) scope_def_ctxt.label_idmap
|
||||
in
|
||||
( Desugared.Ast.LabelMap.find label_id scope_def.scope_def_label_groups,
|
||||
Pos.get_position def.Ast.definition_name )
|
||||
with Not_found ->
|
||||
Errors.raise_spanned_error
|
||||
|
@ -492,15 +492,31 @@ let process_definition (ctxt : context) (s_name : Scopelang.Ast.ScopeName.t) (d
|
||||
match d.Ast.definition_label with
|
||||
| None -> def_key_ctx
|
||||
| Some label ->
|
||||
let new_label_idmap =
|
||||
Desugared.Ast.IdentMap.update (Pos.unmark label)
|
||||
(fun existing_label ->
|
||||
match existing_label with
|
||||
| Some existing_label -> Some existing_label
|
||||
| None -> Some (Desugared.Ast.LabelName.fresh label))
|
||||
def_key_ctx.label_idmap
|
||||
in
|
||||
let label_id =
|
||||
Desugared.Ast.IdentMap.find (Pos.unmark label) new_label_idmap
|
||||
in
|
||||
{
|
||||
def_key_ctx with
|
||||
label_idmap =
|
||||
Desugared.Ast.IdentMap.update (Pos.unmark label)
|
||||
(fun existing_label ->
|
||||
match existing_label with
|
||||
| Some existing_label -> Some existing_label
|
||||
| None -> Some (Desugared.Ast.LabelName.fresh label))
|
||||
def_key_ctx.label_idmap;
|
||||
label_idmap = new_label_idmap;
|
||||
label_groups =
|
||||
Desugared.Ast.LabelMap.update label_id
|
||||
(fun group ->
|
||||
match group with
|
||||
| None ->
|
||||
Some (Desugared.Ast.RuleSet.singleton d.definition_id)
|
||||
| Some existing_group ->
|
||||
Some
|
||||
(Desugared.Ast.RuleSet.add d.definition_id
|
||||
existing_group))
|
||||
def_key_ctx.label_groups;
|
||||
}
|
||||
in
|
||||
(* And second, we update the map of default rulenames for unlabeled
|
||||
|
@ -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_scope/bad/bad_sub_sub_scope.catala_en
|
||||
|
|
||||
25 | definition y under condition a2.x + 1 = 2 consequence equals 1
|
||||
| ^^^^^^^^^^^^
|
||||
| ^
|
||||
+ Article
|
||||
|
||||
This justification is true:
|
||||
This consequence has a valid justification:
|
||||
--> test_scope/bad/bad_sub_sub_scope.catala_en
|
||||
|
|
||||
24 | definition y under condition a2.x = 1 consequence equals 1
|
||||
| ^^^^^^^^
|
||||
| ^
|
||||
+ Article
|
||||
|
@ -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_scope/bad/scope.catala_en
|
||||
|
|
||||
14 | definition b under condition not c consequence equals 0
|
||||
| ^^^^^
|
||||
| ^
|
||||
+ Article
|
||||
|
||||
This justification is true:
|
||||
This consequence has a valid justification:
|
||||
--> test_scope/bad/scope.catala_en
|
||||
|
|
||||
13 | definition b under condition not c consequence equals 1337
|
||||
| ^^^^^
|
||||
| ^^^^
|
||||
+ Article
|
||||
|
Loading…
Reference in New Issue
Block a user