From 31a2a968109145190862f018bab5ae374ff6ba0b Mon Sep 17 00:00:00 2001 From: galfour Date: Wed, 21 Aug 2019 11:41:57 +0200 Subject: [PATCH] fixed last bug --- src/compiler/compiler_program.ml | 2 +- src/contracts/set_arithmetic-1.ligo | 9 +++++++++ src/contracts/set_arithmetic.ligo | 10 ---------- src/test/integration_tests.ml | 9 +++++---- 4 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 src/contracts/set_arithmetic-1.ligo diff --git a/src/compiler/compiler_program.ml b/src/compiler/compiler_program.ml index 8a2ae0d2f..67b9ac634 100644 --- a/src/compiler/compiler_program.ml +++ b/src/compiler/compiler_program.ml @@ -300,7 +300,7 @@ and translate_expression (expr:expression) (env:environment) : michelson result | "ITER" -> ( let%bind code = ok (seq [ expr' ; - i_iter (seq [body' ; dip i_drop]) ; + i_iter (seq [body' ; i_drop ; i_drop]) ; i_push_unit ; ]) in return code diff --git a/src/contracts/set_arithmetic-1.ligo b/src/contracts/set_arithmetic-1.ligo new file mode 100644 index 000000000..2397f72b5 --- /dev/null +++ b/src/contracts/set_arithmetic-1.ligo @@ -0,0 +1,9 @@ +function iter_op (const s : set(int)) : int is + var r : int := 0 ; + function aggregate (const i : int) : unit is + begin + r := r + i ; + end with unit + begin + set_iter(s , aggregate) ; + end with r diff --git a/src/contracts/set_arithmetic.ligo b/src/contracts/set_arithmetic.ligo index 814120c0c..f85e42394 100644 --- a/src/contracts/set_arithmetic.ligo +++ b/src/contracts/set_arithmetic.ligo @@ -1,13 +1,3 @@ -function iter_op (const s : set(int)) : int is - var r : int := 0 ; - function aggregate (const i : int) : unit is - begin - r := r + i ; - end with unit - begin - set_iter(s , aggregate) ; - end with r - const s_e : set(string) = (set_empty : set(string)) const s_fb : set(string) = set [ diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 275479e63..5a4cf635e 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -167,6 +167,11 @@ let string_arithmetic () : unit result = let set_arithmetic () : unit result = let%bind program = type_file "./contracts/set_arithmetic.ligo" in + let%bind program_1 = type_file "./contracts/set_arithmetic-1.ligo" in + let%bind () = + expect_eq program_1 "iter_op" + (e_set [e_int 2 ; e_int 4 ; e_int 7]) + (e_int 13) in let%bind () = expect_eq program "add_op" (e_set [e_string "foo" ; e_string "bar"]) @@ -191,10 +196,6 @@ let set_arithmetic () : unit result = expect_eq program "mem_op" (e_set [e_string "foo" ; e_string "bar"]) (e_bool false) in - let%bind () = - expect_eq program "iter_op" - (e_set [e_int 2 ; e_int 4 ; e_int 7]) - (e_int 13) in ok () let unit_expression () : unit result =