From 5323475097c782c17db5efa9b61ea3d0f0899742 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Mon, 20 Apr 2020 20:21:49 +0200 Subject: [PATCH] empty string singleton is not annotated anymore --- src/bin/expect_tests/michelson_or_tests.ml | 15 ++++++++++++++- src/bin/expect_tests/michelson_pair_test.ml | 14 ++++++++++++++ src/passes/10-transpiler/transpiler.ml | 4 ++-- src/stages/4-ast_typed/helpers.ml | 6 ++++++ .../contracts/michelson_or_tree_intermediary.ligo | 8 ++++++++ .../michelson_pair_tree_intermediary.ligo | 8 ++++++++ 6 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/test/contracts/michelson_or_tree_intermediary.ligo create mode 100644 src/test/contracts/michelson_pair_tree_intermediary.ligo diff --git a/src/bin/expect_tests/michelson_or_tests.ml b/src/bin/expect_tests/michelson_or_tests.ml index 2bf4c6475..66c49dcc0 100644 --- a/src/bin/expect_tests/michelson_or_tests.ml +++ b/src/bin/expect_tests/michelson_or_tests.ml @@ -38,4 +38,17 @@ let%expect_test _ = * Visit our documentation: https://ligolang.org/docs/intro/introduction * Ask a question on our Discord: https://discord.gg/9rhYaEt * Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new - * Check the changelog by running 'ligo changelog' |}] \ No newline at end of file + * Check the changelog by running 'ligo changelog' |}] + +let%expect_test _ = + run_ligo_good [ "compile-contract" ; contract "michelson_or_tree_intermediary.ligo" ; "main" ] ; + [%expect {| + { parameter unit ; + storage (or (int %three) (or (int %one) (nat %two))) ; + code { PUSH int 1 ; + LEFT nat ; + RIGHT int ; + DUP ; + NIL operation ; + PAIR ; + DIP { DROP 2 } } } |}] \ No newline at end of file diff --git a/src/bin/expect_tests/michelson_pair_test.ml b/src/bin/expect_tests/michelson_pair_test.ml index 1b77033e6..623de0b53 100644 --- a/src/bin/expect_tests/michelson_pair_test.ml +++ b/src/bin/expect_tests/michelson_pair_test.ml @@ -43,4 +43,18 @@ let%expect_test _ = PAIR ; NIL operation ; PAIR ; + DIP { DROP } } } |}] + +let%expect_test _ = + run_ligo_good [ "compile-contract" ; contract "michelson_pair_tree_intermediary.ligo" ; "main" ] ; + [%expect {| + { parameter unit ; + storage (pair (string %three) (pair (int %one) (nat %two))) ; + code { PUSH nat 2 ; + PUSH int 1 ; + PAIR ; + PUSH string "foo" ; + PAIR ; + NIL operation ; + PAIR ; DIP { DROP } } } |}] \ No newline at end of file diff --git a/src/passes/10-transpiler/transpiler.ml b/src/passes/10-transpiler/transpiler.ml index f1a764953..6bb73efc0 100644 --- a/src/passes/10-transpiler/transpiler.ml +++ b/src/passes/10-transpiler/transpiler.ml @@ -282,7 +282,7 @@ let rec transpile_type (t:AST.type_expression) : type_value result = let%bind m' = Append_tree.fold_ne (fun (_, ({ctor_type ; michelson_annotation}: AST.ctor_content)) -> let%bind a = transpile_type ctor_type in - ok (michelson_annotation, a) ) + ok (Ast_typed.Helpers.remove_empty_annotation michelson_annotation, a) ) aux node in ok @@ snd m' | T_sum m -> @@ -308,7 +308,7 @@ let rec transpile_type (t:AST.type_expression) : type_value result = let%bind m' = Append_tree.fold_ne (fun (_, ({field_type ; michelson_annotation} : AST.field_content)) -> let%bind a = transpile_type field_type in - ok (michelson_annotation, a) ) + ok (Ast_typed.Helpers.remove_empty_annotation michelson_annotation, a) ) aux node in ok @@ snd m' | T_record m -> diff --git a/src/stages/4-ast_typed/helpers.ml b/src/stages/4-ast_typed/helpers.ml index 4aa1a374b..81d634bb6 100644 --- a/src/stages/4-ast_typed/helpers.ml +++ b/src/stages/4-ast_typed/helpers.ml @@ -166,12 +166,18 @@ let kv_list_of_record_or_tuple (m: _ LMap.t) = List.rev @@ LMap.to_kv_list m +let remove_empty_annotation (ann : string option) : string option = + match ann with + | Some "" -> None + | _ -> ann + let is_michelson_or (t: _ constructor_map) = CMap.cardinal t = 2 && (CMap.mem (Constructor "M_left") t) && (CMap.mem (Constructor "M_right") t) let is_michelson_pair (t: _ label_map) = + LMap.cardinal t = 2 && let l = LMap.to_list t in List.fold_left (fun prev {field_type=_;michelson_annotation} -> match michelson_annotation with diff --git a/src/test/contracts/michelson_or_tree_intermediary.ligo b/src/test/contracts/michelson_or_tree_intermediary.ligo new file mode 100644 index 000000000..3b0e7444e --- /dev/null +++ b/src/test/contracts/michelson_or_tree_intermediary.ligo @@ -0,0 +1,8 @@ +type inner_storage is michelson_or(int,"one",nat,"two") +type storage is michelson_or (int,"three",inner_storage,"") + +type return is list(operation) * storage + +function main (const action : unit; const store : storage) : return is block { + const foo : storage = (M_right ((M_left(1) : inner_storage)) : storage) ; +} with ((nil : list(operation)), (foo: storage)) diff --git a/src/test/contracts/michelson_pair_tree_intermediary.ligo b/src/test/contracts/michelson_pair_tree_intermediary.ligo new file mode 100644 index 000000000..5efc95140 --- /dev/null +++ b/src/test/contracts/michelson_pair_tree_intermediary.ligo @@ -0,0 +1,8 @@ +type inner_storage is michelson_pair(int,"one",nat,"two") +type storage is michelson_pair (string,"three",inner_storage,"") + +type return is list(operation) * storage + +function main (const action : unit; const store : storage) : return is block { + const foo : storage = ("foo",(1,2n)) ; +} with ((nil : list(operation)), (foo: storage))