From 2840eb74144222b85a2bc9649af1101a669ba52f Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Fri, 27 Sep 2019 17:31:38 +0200 Subject: [PATCH] Treat env element expression as deep_closure only if they are lambda --- src/passes/6-transpiler/transpiler.ml | 15 ++++++++++----- src/test/contracts/high-order.ligo | 12 +++++++++++- src/test/integration_tests.ml | 11 +++++++++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/passes/6-transpiler/transpiler.ml b/src/passes/6-transpiler/transpiler.ml index db7fe394a..4d0cec3f0 100644 --- a/src/passes/6-transpiler/transpiler.ml +++ b/src/passes/6-transpiler/transpiler.ml @@ -225,11 +225,16 @@ let rec transpile_literal : AST.literal -> value = fun l -> match l with and transpile_environment_element_type : AST.environment_element -> type_value result = fun ele -> match (AST.get_type' ele.type_value , ele.definition) with | (AST.T_function (f , arg) , ED_declaration (ae , ((_ :: _) as captured_variables)) ) -> - let%bind f' = transpile_type f in - let%bind arg' = transpile_type arg in - let%bind env' = transpile_environment ae.environment in - let sub_env = Mini_c.Environment.select captured_variables env' in - ok @@ Combinators.t_deep_closure sub_env f' arg' + begin + match ae.expression with + | E_lambda _ -> + let%bind f' = transpile_type f in + let%bind arg' = transpile_type arg in + let%bind env' = transpile_environment ae.environment in + let sub_env = Mini_c.Environment.select captured_variables env' in + ok @@ Combinators.t_deep_closure sub_env f' arg' + | _ -> transpile_type ele.type_value + end | _ -> transpile_type ele.type_value and transpile_small_environment : AST.small_environment -> Environment.t result = fun x -> diff --git a/src/test/contracts/high-order.ligo b/src/test/contracts/high-order.ligo index 7c897d4ee..8ab9fdfec 100644 --- a/src/test/contracts/high-order.ligo +++ b/src/test/contracts/high-order.ligo @@ -1,8 +1,18 @@ // Test a PascaLIGO function which takes another PascaLIGO function as an argument - function foobar (const i : int) : int is function foo (const i : int) : int is block { skip } with i ; function bar (const f : int -> int) : int is block { skip } with f ( i ) ; block { skip } with bar (foo) ; + +// higher order function with more than one argument +function higher2(const i: int; const f: int -> int): int is + block { + const ii: int = f(i) + } with ii + +function foobar2 (const i : int) : int is + function foo2 (const i : int) : int is + block { skip } with i; + block { skip } with higher2(i,foo2) \ No newline at end of file diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index fbc966747..e48a10e9a 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -110,8 +110,15 @@ let shadow () : unit result = let higher_order () : unit result = let%bind program = type_file "./contracts/high-order.ligo" in - let make_expect = fun n -> n in - expect_eq_n_int program "foobar" make_expect + let%bind _ = + let make_expect = fun n -> n in + expect_eq_n_int program "foobar" make_expect + in + let%bind _ = + let make_expect = fun n -> n in + expect_eq_n_int program "foobar2" make_expect + in + ok () let shared_function () : unit result = let%bind program = type_file "./contracts/function-shared.ligo" in