From 310dde6dc95a9629c721b4619632129edcea3d1f Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Tue, 17 Dec 2019 21:04:53 +0000 Subject: [PATCH] [LIGO-286] Tuple destructuring doesn't do left hand type inference in CameLIGO --- src/passes/2-simplify/cameligo.ml | 8 ++++---- src/test/contracts/type_tuple_destruct.mligo | 11 +++++++++++ src/test/integration_tests.ml | 7 +++++++ 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/test/contracts/type_tuple_destruct.mligo diff --git a/src/passes/2-simplify/cameligo.ml b/src/passes/2-simplify/cameligo.ml index 054d7272c..530b46042 100644 --- a/src/passes/2-simplify/cameligo.ml +++ b/src/passes/2-simplify/cameligo.ml @@ -564,11 +564,11 @@ and simpl_declaration : Raw.declaration -> declaration Location.wrap list result let%bind (v, v_type) = pattern_to_typed_var par_var in let%bind v_type_expression = match v_type with - | Some v_type -> ok @@ (simpl_type_expression v_type) - | None -> fail @@ wrong_pattern "typed var tuple" par_var in - let%bind v_type_expression = v_type_expression in + | Some v_type -> ok (to_option (simpl_type_expression v_type)) + | None -> ok None + in let%bind simpl_rhs_expr = simpl_expression rhs_expr in - ok @@ loc x @@ Declaration_constant (Var.of_name v.value, Some v_type_expression, simpl_rhs_expr) ) + ok @@ loc x @@ Declaration_constant (Var.of_name v.value, v_type_expression, simpl_rhs_expr) ) in let%bind variables = ok @@ npseq_to_list pt.value in let%bind expr_bind_lst = match let_rhs with diff --git a/src/test/contracts/type_tuple_destruct.mligo b/src/test/contracts/type_tuple_destruct.mligo new file mode 100644 index 000000000..05bcaea59 --- /dev/null +++ b/src/test/contracts/type_tuple_destruct.mligo @@ -0,0 +1,11 @@ +type foobar = int * int +let test_t: foobar = 10, 25 +let foo, bar = test_t + +let type_tuple_d (p: unit) = foo + bar + +type complex = string * int * string * nat +let test_t_2 = "hello", 10, "world", 50n +let hello, ten, world, fifty_n = test_t_2 + +let type_tuple_d_2 (p: unit) = hello ^ world diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 14cc41e23..35ffc05e0 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1765,6 +1765,12 @@ let key_hash () : unit result = let%bind () = expect_eq program "check_hash_key" make_input make_expected in ok () +let type_tuple_destruct () : unit result = + let%bind program = mtype_file "./contracts/type_tuple_destruct.mligo" in + let%bind () = expect_eq program "type_tuple_d" (e_unit ()) (e_int 35) in + let%bind () = expect_eq program "type_tuple_d_2" (e_unit ()) (e_string "helloworld") in + ok () + let main = test_suite "Integration (End to End)" [ test "key hash" key_hash ; test "chain id" chain_id ; @@ -1899,4 +1905,5 @@ let main = test_suite "Integration (End to End)" [ test "simple_access (ligo)" simple_access_ligo; test "deep_access (ligo)" deep_access_ligo; test "entrypoints (ligo)" entrypoints_ligo ; + test "type tuple destruct (mligo)" type_tuple_destruct ; ]