From 0de17f4b57e6f7ce180b13119ddcbd03967c8590 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 10 Oct 2019 13:35:38 -0700 Subject: [PATCH] Add empty set patches, add test for empty set patches --- src/passes/2-simplify/pascaligo.ml | 4 ++-- src/test/contracts/set_arithmetic.ligo | 3 +++ src/test/integration_tests.ml | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/passes/2-simplify/pascaligo.ml b/src/passes/2-simplify/pascaligo.ml index 0a0e252d5..bc29a71d9 100644 --- a/src/passes/2-simplify/pascaligo.ml +++ b/src/passes/2-simplify/pascaligo.ml @@ -828,7 +828,7 @@ and simpl_single_instruction : Raw.single_instr -> (_ -> expression result) resu | MapPatch patch -> fail @@ unsupported_map_patches patch | SetPatch patch -> ( - let setp = patch.value in + let (setp, loc) = r_split patch in let (name , access_path) = simpl_path setp.path in let%bind inj = bind_list @@ List.map (fun (x:Raw.expr) -> @@ -840,7 +840,7 @@ and simpl_single_instruction : Raw.single_instr -> (_ -> expression result) resu e_assign name access_path (e_constant "SET_ADD" [v ; e_variable name]) in let assigns = List.map aux inj in match assigns with - | [] -> fail @@ unsupported_empty_record_patch setp.set_inj + | [] -> ok @@ e_skip ~loc () | hd :: tl -> ( let aux acc cur = e_sequence acc cur in ok @@ List.fold_left aux hd tl diff --git a/src/test/contracts/set_arithmetic.ligo b/src/test/contracts/set_arithmetic.ligo index d1b12195f..1a8e3550f 100644 --- a/src/test/contracts/set_arithmetic.ligo +++ b/src/test/contracts/set_arithmetic.ligo @@ -20,6 +20,9 @@ function remove_syntax (var s : set(string)) : set(string) is function patch_op (var s: set(string)) : set(string) is begin patch s with set ["foobar"]; end with s +function patch_op_empty (var s: set(string)) : set(string) is + begin patch s with set []; end with s + function mem_op (const s : set(string)) : bool is begin skip end with set_mem("foobar" , s) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 3f9c64ced..e82a1b6cd 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -249,6 +249,10 @@ let set_arithmetic () : unit result = expect_eq program "patch_op" (e_set [e_string "foo" ; e_string "bar"]) (e_set [e_string "foo" ; e_string "bar"; e_string "foobar"]) in + let%bind () = + expect_eq program "patch_op_empty" + (e_set [e_string "foo" ; e_string "bar"]) + (e_set [e_string "foo" ; e_string "bar"]) in let%bind () = expect_eq program "mem_op" (e_set [e_string "foo" ; e_string "bar" ; e_string "foobar"])