diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index d818c9d17..0141af522 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -10,7 +10,7 @@ let%expect_test _ = [%expect {| 1872 bytes |}] ; run_ligo_good [ "measure-contract" ; contract "multisig.ligo" ; "main" ] ; - [%expect {| 1294 bytes |}] ; + [%expect {| 1282 bytes |}] ; run_ligo_good [ "measure-contract" ; contract "multisig-v2.ligo" ; "main" ] ; [%expect {| 2974 bytes |}] ; @@ -297,7 +297,7 @@ let%expect_test _ = [%expect {| { parameter (pair (pair (nat %counter) (lambda %message unit (list operation))) - (list %signatures (pair (key_hash %0) (signature %1)))) ; + (list %signatures (pair key_hash signature))) ; storage (pair (pair (list %auth key) (nat %counter)) (pair (string %id) (nat %threshold))) ; code { DUP ; @@ -1173,7 +1173,20 @@ ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, char CONS ; DIP { DIP { DUP } ; SWAP ; CDR } ; PAIR ; - DIP { DROP 2 } } } |}] + DIP { DROP 2 } } } |}]; + + run_ligo_good [ "compile-contract" ; contract "tuples_no_annotation.religo" ; "main" ] ; + [%expect {| + { parameter int ; + storage (pair (pair int string) (pair nat bool)) ; + code { PUSH string "2" ; + PUSH int 2 ; + PAIR ; + DIP { PUSH bool False ; PUSH nat 2 ; PAIR } ; + PAIR ; + NIL operation ; + PAIR ; + DIP { DROP } } } |}] let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "self_type_annotation.ligo" ; "main" ] ; diff --git a/src/bin/expect_tests/michelson_or_tests.ml b/src/bin/expect_tests/michelson_or_tests.ml index 2656620c9..595a76c5e 100644 --- a/src/bin/expect_tests/michelson_or_tests.ml +++ b/src/bin/expect_tests/michelson_or_tests.ml @@ -17,7 +17,7 @@ let%expect_test _ = run_ligo_good [ "compile-contract" ; contract "michelson_or_tree.mligo" ; "main" ] ; [%expect {| { parameter unit ; - storage (or (int %m_left) (or %m_right (int %m_left) (nat %m_right))) ; + storage (or int (or int nat)) ; code { PUSH int 1 ; LEFT nat ; RIGHT int ; diff --git a/src/passes/10-transpiler/transpiler.ml b/src/passes/10-transpiler/transpiler.ml index ff4b0c626..7168af974 100644 --- a/src/passes/10-transpiler/transpiler.ml +++ b/src/passes/10-transpiler/transpiler.ml @@ -278,6 +278,7 @@ let rec transpile_type (t:AST.type_expression) : type_value result = ) (* TODO hmm *) | T_sum m -> + let is_michelson_or = Ast_typed.Helpers.is_michelson_or m in let node = Append_tree.of_list @@ kv_list_of_cmap m in let aux a b : type_value annotated result = let%bind a = a in @@ -287,11 +288,23 @@ let rec transpile_type (t:AST.type_expression) : type_value result = let%bind m' = Append_tree.fold_ne (fun (Ast_typed.Types.Constructor ann, a) -> let%bind a = transpile_type a in - ok (Some (String.uncapitalize_ascii ann), a)) + ok (( + if is_michelson_or then + None + else + Some (String.uncapitalize_ascii ann)), + a)) aux node in ok @@ snd m' | T_record m -> - let node = Append_tree.of_list @@ Ast_typed.Helpers.kv_list_of_record_or_tuple m in + let is_tuple_lmap = Ast_typed.Helpers.is_tuple_lmap m in + let node = Append_tree.of_list @@ ( + if is_tuple_lmap then + Ast_typed.Helpers.tuple_of_record m + else + List.rev @@ Ast_typed.Types.LMap.to_kv_list m + ) + in let aux a b : type_value annotated result = let%bind a = a in let%bind b = b in @@ -299,8 +312,13 @@ let rec transpile_type (t:AST.type_expression) : type_value result = in let%bind m' = Append_tree.fold_ne (fun (Ast_typed.Types.Label ann, a) -> - let%bind a = transpile_type a in - ok (Some ann, a)) + let%bind a = transpile_type a in + ok ((if is_tuple_lmap then + None + else + Some ann), + a) + ) aux node in ok @@ snd m' | T_arrow {type1;type2} -> ( diff --git a/src/stages/4-ast_typed/helpers.ml b/src/stages/4-ast_typed/helpers.ml index bb3962846..c7dff6989 100644 --- a/src/stages/4-ast_typed/helpers.ml +++ b/src/stages/4-ast_typed/helpers.ml @@ -163,3 +163,9 @@ let kv_list_of_record_or_tuple (m: _ LMap.t) = tuple_of_record m else List.rev @@ LMap.to_kv_list m + + +let is_michelson_or (t: _ constructor_map) = + CMap.cardinal t = 2 && + (CMap.mem (Constructor "M_left") t) && + (CMap.mem (Constructor "M_right") t) \ No newline at end of file diff --git a/src/stages/common/helpers.ml b/src/stages/common/helpers.ml index 91cd0eae1..dded3a7d8 100644 --- a/src/stages/common/helpers.ml +++ b/src/stages/common/helpers.ml @@ -66,3 +66,4 @@ let kv_list_of_record_or_tuple (m: _ LMap.t) = tuple_of_record m else List.rev @@ LMap.to_kv_list m + diff --git a/src/stages/common/helpers.mli b/src/stages/common/helpers.mli index 1292bb807..03817d6d4 100644 --- a/src/stages/common/helpers.mli +++ b/src/stages/common/helpers.mli @@ -26,7 +26,6 @@ val list_of_record_or_tuple : 'a LMap.t -> 'a list val kv_list_of_record_or_tuple : 'a LMap.t -> (label * 'a) list - val bind_map_lmapi : (Types.label -> 'a -> ('b * 'c list, 'd) result) -> 'a Types.label_map -> ('b Types.label_map * 'c list, 'd) result diff --git a/src/test/contracts/tuples_no_annotation.religo b/src/test/contracts/tuples_no_annotation.religo new file mode 100644 index 000000000..6858c60a5 --- /dev/null +++ b/src/test/contracts/tuples_no_annotation.religo @@ -0,0 +1,7 @@ +type storage = (int, string, nat, bool) + +type parameter = int + +let main = ((p,storage): (parameter, storage)) => { +([]: list (operation), (2, "2", 2n, false)); +};