Check for closure when applying a function and update tests

This commit is contained in:
Lesenechal Remi 2019-10-02 17:28:11 +02:00
parent a7565145d5
commit 6fbe43d28a
3 changed files with 21 additions and 11 deletions

View File

@ -280,7 +280,13 @@ and transpile_annotated_expression (ae:AST.annotated_expression) : expression re
| E_application (a, b) -> | E_application (a, b) ->
let%bind a = transpile_annotated_expression a in let%bind a = transpile_annotated_expression a in
let%bind b = transpile_annotated_expression b in let%bind b = transpile_annotated_expression b in
return @@ E_application (a, b) let%bind b' = Self_mini_c.Helpers.map_expression
(fun exp ->
match exp.type_value with
| T_deep_closure _ -> fail @@ simple_error "Cannot apply closure in function argument"
| _ -> ok exp
) b in
return @@ E_application (a, b')
| E_constructor (m, param) -> ( | E_constructor (m, param) -> (
let%bind param' = transpile_annotated_expression param in let%bind param' = transpile_annotated_expression param in
let (param'_expr , param'_tv) = Combinators.Expression.(get_content param' , get_type param') in let (param'_expr , param'_tv) = Combinators.Expression.(get_content param' , get_type param') in

View File

@ -15,4 +15,11 @@ function higher2(const i: int; const f: int -> int): int is
function foobar2 (const i : int) : int is function foobar2 (const i : int) : int is
function foo2 (const i : int) : int is function foo2 (const i : int) : int is
block { skip } with i; block { skip } with i;
block { skip } with higher2(i,foo2) block { skip } with higher2(i,foo2)
// This is not supported yet:
// const a : int = 123;
// function foobar3 (const i : int) : int is
// function foo2 (const i : int) : int is
// block { skip } with (a+i);
// block { skip } with higher2(i,foo2)

View File

@ -110,15 +110,12 @@ let shadow () : unit result =
let higher_order () : unit result = let higher_order () : unit result =
let%bind program = type_file "./contracts/high-order.ligo" in let%bind program = type_file "./contracts/high-order.ligo" in
let%bind _ = let make_expect = fun n -> n in
let make_expect = fun n -> n in let%bind _ = expect_eq_n_int program "foobar" make_expect in
expect_eq_n_int program "foobar" make_expect let%bind _ = expect_eq_n_int program "foobar2" make_expect in
in (* not supported yet:
let%bind _ = let%bind _ = expect_eq_n_int program "foobar3" make_expect in *)
let make_expect = fun n -> n in ok ()
expect_eq_n_int program "foobar2" make_expect
in
ok ()
let shared_function () : unit result = let shared_function () : unit result =
let%bind program = type_file "./contracts/function-shared.ligo" in let%bind program = type_file "./contracts/function-shared.ligo" in