From 9cf55b0edd6f9bd84ad456e7a800b8bca584d42e Mon Sep 17 00:00:00 2001 From: Denis Merigoux Date: Sun, 18 Jun 2023 15:49:02 +0200 Subject: [PATCH] Closure env is unit if no extra variable captured --- compiler/lcalc/closure_conversion.ml | 14 ++++++++------ .../good/scope_call_func_struct_closure.catala_en | 1 - 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/compiler/lcalc/closure_conversion.ml b/compiler/lcalc/closure_conversion.ml index 1eac038a..11622362 100644 --- a/compiler/lcalc/closure_conversion.ml +++ b/compiler/lcalc/closure_conversion.ml @@ -204,12 +204,14 @@ let rec transform_closures_expr : [TAny, Expr.pos e] (Mark.get e)) [ - Expr.etuple - (List.map - (fun extra_var -> - Bindlib.box_var extra_var, binder_mark) - extra_vars_list) - m; + (if extra_vars_list = [] then Expr.elit LUnit binder_mark + else + Expr.etuple + (List.map + (fun extra_var -> + Bindlib.box_var extra_var, binder_mark) + extra_vars_list) + m); ] (Mark.get e); ]) diff --git a/tests/test_func/good/scope_call_func_struct_closure.catala_en b/tests/test_func/good/scope_call_func_struct_closure.catala_en index 14d5c543..06c3aba1 100644 --- a/tests/test_func/good/scope_call_func_struct_closure.catala_en +++ b/tests/test_func/good/scope_call_func_struct_closure.catala_en @@ -39,7 +39,6 @@ scope Foo: This test case is tricky because it creates a situation where the type of the two closures in Foo.r are different even with optimizations enabled. -TODO fix this. ```catala-test-inline $ catala Lcalc --avoid_exceptions -O --closure_conversion -s Foo