mirror of
https://github.com/CatalaLang/catala.git
synced 2024-09-19 16:28:12 +03:00
Fix tests [skip ci]
This commit is contained in:
parent
cb04ef3f9d
commit
a8733e6a61
@ -124,8 +124,8 @@ let rec rule_tree_to_expr ~(toplevel : bool) (def_pos : Pos.t)
|
||||
(** Translates a definition inside a scope, the resulting expression should be an {!constructor:
|
||||
Dcalc.Ast.EDefault} *)
|
||||
let translate_def (def_info : Ast.ScopeDef.t) (def : Ast.rule Ast.RuleMap.t)
|
||||
(typ : Scopelang.Ast.typ Pos.marked) ~(is_cond : bool) ~(is_subscope_var : bool) :
|
||||
Scopelang.Ast.expr Pos.marked =
|
||||
(typ : Scopelang.Ast.typ Pos.marked) (io : Scopelang.Ast.io) ~(is_cond : bool)
|
||||
~(is_subscope_var : bool) : Scopelang.Ast.expr Pos.marked =
|
||||
(* Here, we have to transform this list of rules into a default tree. *)
|
||||
let is_def_func = match Pos.unmark typ with Scopelang.Ast.TArrow (_, _) -> true | _ -> false in
|
||||
let is_rule_func _ (r : Ast.rule) : bool = Option.is_some r.Ast.rule_parameter in
|
||||
@ -161,7 +161,8 @@ let translate_def (def_info : Ast.ScopeDef.t) (def : Ast.rule Ast.RuleMap.t)
|
||||
(if is_cond then Ast.always_false_rule else Ast.empty_rule) Pos.no_pos is_def_func_param_typ
|
||||
in
|
||||
if
|
||||
Ast.RuleMap.cardinal def = 0 && is_subscope_var
|
||||
Ast.RuleMap.cardinal def = 0
|
||||
&& is_subscope_var
|
||||
(* Here we have a special case for the empty definitions. Indeed, we could use the code for the
|
||||
regular case below that would create a convoluted default always returning empty error, and
|
||||
this would be correct. But it gets more complicated with functions. Indeed, if we create an
|
||||
@ -176,6 +177,12 @@ let translate_def (def_info : Ast.ScopeDef.t) (def : Ast.rule Ast.RuleMap.t)
|
||||
To avoid this complication we special case here and put an empty error for all subscope
|
||||
variables that are not defined. It covers the subtlety with functions described above but
|
||||
also conditions with the false default value. *)
|
||||
&& not
|
||||
(is_cond
|
||||
&& match Pos.unmark io.Scopelang.Ast.io_input with OnlyInput -> true | _ -> false)
|
||||
(* However, this special case suffers from an exception: when a condition is defined as an
|
||||
OnlyInput to a subscope, since the [false] default value will not be provided by the calee
|
||||
scope, it has to be placed in the caller. *)
|
||||
then (ELit LEmptyError, Pos.no_pos)
|
||||
else
|
||||
Bindlib.unbox
|
||||
@ -218,8 +225,8 @@ let translate_scope (scope : Ast.scope) : Scopelang.Ast.scope_decl =
|
||||
| OnlyInput -> [] (* we do not provide any definition for an input-only variable *)
|
||||
| _ ->
|
||||
let expr_def =
|
||||
translate_def (Ast.ScopeDef.Var var) var_def var_typ ~is_cond
|
||||
~is_subscope_var:false
|
||||
translate_def (Ast.ScopeDef.Var var) var_def var_typ scope_def.Ast.scope_def_io
|
||||
~is_cond ~is_subscope_var:false
|
||||
in
|
||||
[
|
||||
Scopelang.Ast.Definition
|
||||
@ -281,7 +288,8 @@ let translate_scope (scope : Ast.scope) : Scopelang.Ast.scope_decl =
|
||||
(* Now that all is good, we can proceed with translating this redefinition
|
||||
to a proper Scopelang term. *)
|
||||
let expr_def =
|
||||
translate_def def_key def def_typ ~is_cond ~is_subscope_var:true
|
||||
translate_def def_key def def_typ scope_def.Ast.scope_def_io ~is_cond
|
||||
~is_subscope_var:true
|
||||
in
|
||||
let subscop_real_name =
|
||||
Scopelang.Ast.SubScopeMap.find sub_scope_index scope.scope_sub_scopes
|
||||
|
@ -371,7 +371,7 @@ let translate_rule (ctx : ctx) (rule : Ast.rule)
|
||||
| NoInput -> failwith "should not happen"
|
||||
| OnlyInput ->
|
||||
Bindlib.box_apply
|
||||
(fun new_e -> (Dcalc.Ast.ErrorOnEmpty new_e, Pos.get_position a_name))
|
||||
(fun new_e -> (Dcalc.Ast.ErrorOnEmpty new_e, Pos.get_position subs_var))
|
||||
new_e
|
||||
| Reentrant ->
|
||||
Dcalc.Ast.make_abs
|
||||
|
@ -6,8 +6,8 @@ declaration structure Period:
|
||||
data end content date
|
||||
|
||||
declaration scope PeriodMerge:
|
||||
input periods1 content collection Period
|
||||
input periods2 content collection Period
|
||||
context periods1 content collection Period
|
||||
context periods2 content collection Period
|
||||
output output_periods content collection Period
|
||||
|
||||
scope PeriodMerge:
|
||||
@ -45,7 +45,7 @@ declaration scope Section121SinglePerson:
|
||||
input gain_from_sale_or_exchange_of_property content money
|
||||
output income_excluded_from_gross_income_uncapped content money
|
||||
output income_excluded_from_gross_income content money
|
||||
input output section_121_b_3_applies condition
|
||||
context output section_121_b_3_applies condition
|
||||
input other_section_121a_sale content OtherSection121aSale
|
||||
|
||||
declaration structure PersonalData:
|
||||
@ -69,9 +69,9 @@ declaration enumeration ReturnType:
|
||||
-- SingleReturnSurvivingSpouse content DeadSpouseInfo
|
||||
|
||||
declaration scope Section121TwoPersons:
|
||||
input output person1 content PersonalData
|
||||
context output person1 content PersonalData
|
||||
section121Person1 scope Section121SinglePerson
|
||||
input output person2 content PersonalData
|
||||
context output person2 content PersonalData
|
||||
section121Person2 scope Section121SinglePerson
|
||||
internal section121a_requirements_met condition
|
||||
output section_121_b_2_A_condition condition
|
||||
|
@ -12,7 +12,7 @@ declaration scope QualifiedEmployeeDiscount:
|
||||
output gross_profit_percentage content decimal
|
||||
output qualified_employee_discount content money
|
||||
output employee_discount content money
|
||||
input aggregate_cost content money
|
||||
context aggregate_cost content money
|
||||
input discount_type content DiscountType
|
||||
internal is_property content boolean
|
||||
internal is_services content boolean
|
||||
|
16
tests/test_visibility/good/condition_only_input.catala_en
Normal file
16
tests/test_visibility/good/condition_only_input.catala_en
Normal file
@ -0,0 +1,16 @@
|
||||
# Test
|
||||
|
||||
```catala
|
||||
declaration scope A:
|
||||
input x condition
|
||||
output y content integer
|
||||
|
||||
declaration scope B:
|
||||
a scope A
|
||||
|
||||
scope A:
|
||||
definition y equals if x then 0 else 1
|
||||
|
||||
scope B:
|
||||
assertion a.y = 1
|
||||
```
|
@ -0,0 +1 @@
|
||||
[RESULT] Computation successful!
|
Loading…
Reference in New Issue
Block a user