From 5159f293f81d9189281b2f0cd6038a5523f65053 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Thu, 27 Feb 2020 01:36:56 +0100 Subject: [PATCH 1/9] Repare function annotation in let binding for Camligo and ReasonLigo and fix some contracts --- .../docs/language-basics/functions.md | 2 +- .../docs/language-basics/maps-records.md | 4 +-- gitlab-pages/docs/reference/map.md | 4 +-- src/passes/2-simplify/cameligo.ml | 30 +++++++++++++++---- src/test/contracts/failwith.mligo | 2 +- src/test/contracts/let_in_multi_bind.mligo | 2 +- src/test/contracts/map.mligo | 4 +-- .../contracts/negative/self_in_lambda.mligo | 4 +-- src/test/contracts/set_arithmetic.mligo | 2 +- 9 files changed, 37 insertions(+), 17 deletions(-) diff --git a/gitlab-pages/docs/language-basics/functions.md b/gitlab-pages/docs/language-basics/functions.md index b4c81beb1..9f55eec5c 100644 --- a/gitlab-pages/docs/language-basics/functions.md +++ b/gitlab-pages/docs/language-basics/functions.md @@ -133,7 +133,7 @@ returns an integer as well: ```cameligo group=b let add (a, b : int * int) : int = a + b // Uncurried let add_curry (a : int) (b : int) : int = add (a, b) // Curried -let increment (b : int) : int = add_curry 1 // Partial application +let increment (b : int) : int = add_curry 1 b // Partial application ``` You can run the `increment` function defined above using the LIGO diff --git a/gitlab-pages/docs/language-basics/maps-records.md b/gitlab-pages/docs/language-basics/maps-records.md index c9837fb26..fda74b822 100644 --- a/gitlab-pages/docs/language-basics/maps-records.md +++ b/gitlab-pages/docs/language-basics/maps-records.md @@ -697,7 +697,7 @@ function fold_op (const m : register) : int is ```cameligo group=maps -let fold_op (m : register) : register = +let fold_op (m : register) : int = let folded = fun (i,j : int * (address * move)) -> i + j.1.1 in Map.fold folded m 5 ``` @@ -705,7 +705,7 @@ let fold_op (m : register) : register = ```reasonligo group=maps -let fold_op = (m : register) : register => { +let fold_op = (m : register) : int => { let folded = ((i,j): (int, (address, move))) => i + j[1][1]; Map.fold (folded, m, 5); }; diff --git a/gitlab-pages/docs/reference/map.md b/gitlab-pages/docs/reference/map.md index df3ecbb31..529de3edf 100644 --- a/gitlab-pages/docs/reference/map.md +++ b/gitlab-pages/docs/reference/map.md @@ -341,14 +341,14 @@ function fold_op (const m : register) : int is ```cameligo group=maps -let fold_op (m : register) : register = +let fold_op (m : register) : int = let folded = fun (i,j : int * (address * move)) -> i + j.1.1 in Map.fold folded m 5 ``` ```reasonligo group=maps -let fold_op = (m : register) : register => { +let fold_op = (m : register) : int => { let folded = ((i,j): (int, (address, move))) => i + j[1][1]; Map.fold (folded, m, 5); }; diff --git a/src/passes/2-simplify/cameligo.ml b/src/passes/2-simplify/cameligo.ml index 1680caf96..d9f516ae8 100644 --- a/src/passes/2-simplify/cameligo.ml +++ b/src/passes/2-simplify/cameligo.ml @@ -156,6 +156,14 @@ let rec pattern_to_var : Raw.pattern -> _ = fun p -> | Raw.PWild r -> ok @@ ({ region = r ; value = "_" } : Raw.variable) | _ -> fail @@ wrong_pattern "single var" p +let rec tuple_pattern_to_vars : Raw.pattern -> _ = fun pattern -> + match pattern with + | Raw.PPar pp -> tuple_pattern_to_vars pp.value.inside + | Raw.PTuple pt -> bind_map_list pattern_to_var (npseq_to_list pt.value) + | Raw.PVar _ | Raw.PWild _-> bind_list [pattern_to_var pattern] + | other -> (fail @@ wrong_pattern "parenthetical, tuple, or variable" other) + + let rec pattern_to_typed_var : Raw.pattern -> _ = fun p -> match p with | Raw.PPar p -> pattern_to_typed_var p.value.inside @@ -180,11 +188,21 @@ let rec tuple_pattern_to_typed_vars : Raw.pattern -> _ = fun pattern -> | Raw.PVar _ -> bind_list [pattern_to_typed_var pattern] | other -> (fail @@ wrong_pattern "parenthetical, tuple, or variable" other) -let rec unpar_pattern : Raw.pattern -> Raw.pattern = function +let rec typed_pattern_to_typed_vars : Raw.pattern -> _ = fun pattern -> + match pattern with + | Raw.PPar pp -> typed_pattern_to_typed_vars pp.value.inside + | Raw.PTyped pt -> + let (p,t) = pt.value.pattern,pt.value.type_expr in + let%bind p = tuple_pattern_to_vars p in + let%bind t = simpl_type_expression t in + ok @@ (p,t) + | other -> (fail @@ wrong_pattern "parenthetical or type annotation" other) + +and unpar_pattern : Raw.pattern -> Raw.pattern = function | PPar p -> unpar_pattern p.value.inside | _ as p -> p -let rec simpl_type_expression : Raw.type_expr -> type_expression result = fun te -> +and simpl_type_expression : Raw.type_expr -> type_expression result = fun te -> trace (simple_info "simplifying this type expression...") @@ match te with TPar x -> simpl_type_expression x.value.inside @@ -793,10 +811,9 @@ and simpl_declaration : Raw.declaration -> declaration Location.wrap list result let%bind var = pattern_to_var hd in ok (var , tl) in + let%bind lhs_type' = bind_map_option (fun x -> simpl_type_expression (snd x)) lhs_type in match args with | [] -> - let%bind lhs_type' = - bind_map_option (fun (_,te) -> simpl_type_expression te) lhs_type in let%bind rhs' = simpl_expression let_rhs in ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , lhs_type' , inline, rhs'))] | param1::others -> @@ -809,7 +826,10 @@ and simpl_declaration : Raw.declaration -> declaration Location.wrap list result } in let rhs = Raw.EFun {region=Region.ghost ; value=fun_} in let%bind rhs' = simpl_expression rhs in - ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , None , inline, rhs'))] + let%bind ty = bind_map_list typed_pattern_to_typed_vars args in + let aux acc ty = Option.map (t_function (snd ty)) acc in + let func_type = List.fold_right' aux lhs_type' ty in + ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , func_type , inline, rhs'))] ) and simpl_cases : type a . (Raw.pattern * a) list -> (a, unit) matching_content result = diff --git a/src/test/contracts/failwith.mligo b/src/test/contracts/failwith.mligo index fbc5976bd..b2f7411da 100644 --- a/src/test/contracts/failwith.mligo +++ b/src/test/contracts/failwith.mligo @@ -1,4 +1,4 @@ type storage = unit -let main (p: unit) storage = +let main (p: unit) (s:storage) = if true then failwith "This contract always fails" else () diff --git a/src/test/contracts/let_in_multi_bind.mligo b/src/test/contracts/let_in_multi_bind.mligo index e61dc14a7..f6e11b035 100644 --- a/src/test/contracts/let_in_multi_bind.mligo +++ b/src/test/contracts/let_in_multi_bind.mligo @@ -1,5 +1,5 @@ let sum (p: int * int) : int = let i, result = p in i + result -let sum2 (p: string * string * string * string) : int = +let sum2 (p: string * string * string * string) : string = let a, b, c, d = p in a ^ b ^ c ^ d diff --git a/src/test/contracts/map.mligo b/src/test/contracts/map.mligo index 7b13f406c..5ad4246f7 100644 --- a/src/test/contracts/map.mligo +++ b/src/test/contracts/map.mligo @@ -42,8 +42,8 @@ let map_op (m : foobar) : foobar = let increment = fun (i: int * int) -> i.1 + 1 in Map.map increment m -let fold_op (m : foobar) : foobar = - let aggregate = fun (i: int * (int * int)) -> i.0 + i.1.0 + i.1.1 +let fold_op (m : foobar) : int = + let aggregate = fun (i,m: int * (int * int)) -> i + m.0 + m.1 in Map.fold aggregate m 10 let deep_op (m: foobar) : foobar = diff --git a/src/test/contracts/negative/self_in_lambda.mligo b/src/test/contracts/negative/self_in_lambda.mligo index 493047199..9595b752d 100644 --- a/src/test/contracts/negative/self_in_lambda.mligo +++ b/src/test/contracts/negative/self_in_lambda.mligo @@ -1,5 +1,5 @@ let foo (u: unit) : address = Current.self_address -let main (ps: unit * address): (operation list * address) = - ( ([] : operation list) , foo) \ No newline at end of file +let main (ps: unit * address): (operation list * (unit -> address)) = + ( ([] : operation list) , foo) diff --git a/src/test/contracts/set_arithmetic.mligo b/src/test/contracts/set_arithmetic.mligo index 2713905b3..0eff261f7 100644 --- a/src/test/contracts/set_arithmetic.mligo +++ b/src/test/contracts/set_arithmetic.mligo @@ -9,7 +9,7 @@ let add_op (s : string set) : string set = let remove_op (s : string set) : string set = Set.remove "foobar" s -let remove_deep (s : string set * nat) : string set * nat = +let remove_deep (s : string set * nat) : string set = Set.remove "foobar" s.0 (* From 6e35dadcc4e854584cf6388531e7b57b96934123 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Thu, 27 Feb 2020 12:04:53 +0100 Subject: [PATCH 2/9] fix self_in_lambda.mligo --- src/test/contracts/negative/self_in_lambda.mligo | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/contracts/negative/self_in_lambda.mligo b/src/test/contracts/negative/self_in_lambda.mligo index 9595b752d..982973973 100644 --- a/src/test/contracts/negative/self_in_lambda.mligo +++ b/src/test/contracts/negative/self_in_lambda.mligo @@ -1,5 +1,6 @@ let foo (u: unit) : address = Current.self_address -let main (ps: unit * address): (operation list * (unit -> address)) = - ( ([] : operation list) , foo) +let main (ps: unit * address): (operation list * address) = + let dummy = foo() in + ( ([] : operation list) , foo()) From 89f2b44e7d2b0971f3585b8866ea5e1515a2520a Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Thu, 27 Feb 2020 12:38:00 +0100 Subject: [PATCH 3/9] Works also when the function parameter are passed in the rhs Fix some religo contract --- src/passes/2-simplify/cameligo.ml | 24 +++++++++++++--------- src/test/contracts/balance_constant.religo | 2 +- src/test/contracts/counter.religo | 3 +-- src/test/contracts/lambda.religo | 2 +- src/test/contracts/lambda2.religo | 2 +- src/test/contracts/letin.religo | 4 ++-- src/test/contracts/list.religo | 2 +- src/test/contracts/match.religo | 4 ++-- src/test/contracts/match_bis.religo | 2 +- 9 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/passes/2-simplify/cameligo.ml b/src/passes/2-simplify/cameligo.ml index d9f516ae8..222dee09f 100644 --- a/src/passes/2-simplify/cameligo.ml +++ b/src/passes/2-simplify/cameligo.ml @@ -812,10 +812,8 @@ and simpl_declaration : Raw.declaration -> declaration Location.wrap list result ok (var , tl) in let%bind lhs_type' = bind_map_option (fun x -> simpl_type_expression (snd x)) lhs_type in - match args with - | [] -> - let%bind rhs' = simpl_expression let_rhs in - ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , lhs_type' , inline, rhs'))] + let let_rhs = match args with + | [] -> let_rhs | param1::others -> let fun_ = { kwd_fun = Region.ghost; @@ -824,12 +822,18 @@ and simpl_declaration : Raw.declaration -> declaration Location.wrap list result arrow = Region.ghost; body = let_rhs } in - let rhs = Raw.EFun {region=Region.ghost ; value=fun_} in - let%bind rhs' = simpl_expression rhs in - let%bind ty = bind_map_list typed_pattern_to_typed_vars args in - let aux acc ty = Option.map (t_function (snd ty)) acc in - let func_type = List.fold_right' aux lhs_type' ty in - ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , func_type , inline, rhs'))] + Raw.EFun {region=Region.ghost ; value=fun_} + in + let f_args = (match let_rhs with + | Raw.EFun f -> nseq_to_list f.value.binders + | _ -> [] + ) + in + let%bind rhs' = simpl_expression let_rhs in + let%bind ty = bind_map_list typed_pattern_to_typed_vars f_args in + let aux acc ty = Option.map (t_function (snd ty)) acc in + let func_type = List.fold_right' aux lhs_type' ty in + ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , func_type , inline, rhs'))] ) and simpl_cases : type a . (Raw.pattern * a) list -> (a, unit) matching_content result = diff --git a/src/test/contracts/balance_constant.religo b/src/test/contracts/balance_constant.religo index efa80fc48..52373431f 100644 --- a/src/test/contracts/balance_constant.religo +++ b/src/test/contracts/balance_constant.religo @@ -12,6 +12,6 @@ generated. unrecognized constant: {"constant":"BALANCE","location":"generated"} type storage = tez; -let main2 = (p: unit, storage) => ([]: list(operation), balance); +let main2 = (p: unit, s: storage) => ([]: list(operation), balance); let main = (x: (unit, storage)) => main2(x[0],x[1]); diff --git a/src/test/contracts/counter.religo b/src/test/contracts/counter.religo index 8ed3f201f..773c94deb 100644 --- a/src/test/contracts/counter.religo +++ b/src/test/contracts/counter.religo @@ -1,7 +1,6 @@ type storage = int; -let main2 = (p: int, storage): string => ([]: list(operation), p + storage); +let main2 = (p: int, s: storage): string => ([]: list(operation), p + s); let main = (x: (int, storage)) : string => main2(x[0],x[1]); - diff --git a/src/test/contracts/lambda.religo b/src/test/contracts/lambda.religo index 19d885228..6a997e826 100644 --- a/src/test/contracts/lambda.religo +++ b/src/test/contracts/lambda.religo @@ -5,6 +5,6 @@ type storage = unit; (fun x -> ()) () */ -let main2 = ((p: unit), storage) => (((xxx: unit)) => ())(); +let main2 = ((p: unit), s: storage) => (((xxx: unit)) => ())(); let main = (x: (unit, storage)) => main2(x[0], x[1]); diff --git a/src/test/contracts/lambda2.religo b/src/test/contracts/lambda2.religo index fd6a6bd27..4be943b06 100644 --- a/src/test/contracts/lambda2.religo +++ b/src/test/contracts/lambda2.religo @@ -4,7 +4,7 @@ type storage = unit; let main (p:unit) storage = (fun x -> ()) () */ -let main2 = (z: unit, storage) => +let main2 = (z: unit, s: storage) => ((f: (unit => unit)) => f())((z: unit) => unit); let main = (x: (unit, storage)) => main2(x[0],x[1]); diff --git a/src/test/contracts/letin.religo b/src/test/contracts/letin.religo index b370c0a59..22b08bda9 100644 --- a/src/test/contracts/letin.religo +++ b/src/test/contracts/letin.religo @@ -1,9 +1,9 @@ type storage = (int, int); -let main2 = ((n : int), storage) => { +let main2 = ((n : int), s: storage) => { let x: (int, int) = { let x: int = 7; - (x + n, storage[0] + storage[1]); + (x + n, s[0] + s[1]); }; ([]: list(operation), x); }; diff --git a/src/test/contracts/list.religo b/src/test/contracts/list.religo index 9f9a2ec1c..5dc8f17d2 100644 --- a/src/test/contracts/list.religo +++ b/src/test/contracts/list.religo @@ -6,7 +6,7 @@ let x: list(int) = []; let y: list(int) = [3, 4, 5]; let z: list(int) = [2, ...y]; -let main2 = (p: param, storage) => { +let main2 = (p: param, storage : storage) => { let storage = switch (p) { | [] => storage diff --git a/src/test/contracts/match.religo b/src/test/contracts/match.religo index 3f77b252d..361443089 100644 --- a/src/test/contracts/match.religo +++ b/src/test/contracts/match.religo @@ -4,9 +4,9 @@ type param = | Add(int) | Sub(int); -let main2 = ((p: param), storage) => { +let main2 = ((p: param), s: storage) => { let storage = - storage + s + ( switch (p) { | Add(n) => n diff --git a/src/test/contracts/match_bis.religo b/src/test/contracts/match_bis.religo index d1465d77b..ece959639 100644 --- a/src/test/contracts/match_bis.religo +++ b/src/test/contracts/match_bis.religo @@ -12,7 +12,7 @@ let subtract = ((a: int), (b: int)) => a - b; /* real entrypoint that re-routes the flow based on the action provided */ -let main2 = ((p: action), storage) => { +let main2 = ((p: action), storage : storage) => { let storage = switch (p) { | Increment(n) => add(storage, n) From 32d3bb5a0f6e3a6e8fa79b1201cf92c63ae00919 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Mon, 2 Mar 2020 18:20:15 +0100 Subject: [PATCH 4/9] fixing doc or fonction (partial application) --- gitlab-pages/docs/language-basics/functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab-pages/docs/language-basics/functions.md b/gitlab-pages/docs/language-basics/functions.md index 9f55eec5c..bab722159 100644 --- a/gitlab-pages/docs/language-basics/functions.md +++ b/gitlab-pages/docs/language-basics/functions.md @@ -133,7 +133,7 @@ returns an integer as well: ```cameligo group=b let add (a, b : int * int) : int = a + b // Uncurried let add_curry (a : int) (b : int) : int = add (a, b) // Curried -let increment (b : int) : int = add_curry 1 b // Partial application +let increment : int -> int = add_curry 1 // Partial application ``` You can run the `increment` function defined above using the LIGO From a19e2ceb3bd6e8770c2e3df01cf27d23d7b24c42 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Tue, 3 Mar 2020 14:39:00 +0100 Subject: [PATCH 5/9] adding negative test --- src/bin/expect_tests/typer_error_tests.ml | 15 ++++++++++++++- .../negative/error_function_annotation.mligo | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/test/contracts/negative/error_function_annotation.mligo diff --git a/src/bin/expect_tests/typer_error_tests.ml b/src/bin/expect_tests/typer_error_tests.ml index 4aa7b95e8..32eb559d7 100644 --- a/src/bin/expect_tests/typer_error_tests.ml +++ b/src/bin/expect_tests/typer_error_tests.ml @@ -1,6 +1,19 @@ open Cli_expect let%expect_test _ = + run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_annotation.mligo"; "main"]; + [%expect {| + ligo: in file "", line 0, characters 0-0. different type constructors: Expected these two constant type constructors to be the same, but they're different {"a":"unit","b":"int"} + + + If you're not sure how to fix this error, you can + do one of the following: + + * Visit our documentation: https://ligolang.org/docs/intro/what-and-why/ + * 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' |}]; + run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_type.ligo" ; "main" ] ; [%expect {| ligo: in file "error_type.ligo", line 3, characters 18-28. Adding modulo with wrong types: Expected arguments with one of the following combinations of types: add(nat , nat) or add(int , int) or add(mutez , mutez) or add(nat , int) or add(int , nat) or add(timestamp , int) or add(int , timestamp) but got this combination instead: add(int , string) @@ -135,4 +148,4 @@ let%expect_test _ = * Visit our documentation: https://ligolang.org/docs/intro/what-and-why/ * 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' |}]; diff --git a/src/test/contracts/negative/error_function_annotation.mligo b/src/test/contracts/negative/error_function_annotation.mligo new file mode 100644 index 000000000..3360a7b1a --- /dev/null +++ b/src/test/contracts/negative/error_function_annotation.mligo @@ -0,0 +1 @@ +let main (a:int) : unit = a From 4f13a33d46b2b18a409debab89e76f72de9a533b Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Tue, 3 Mar 2020 16:17:07 +0100 Subject: [PATCH 6/9] fix bug with wrong annotation at the beginning --- src/passes/2-simplify/cameligo.ml | 19 +++++++------------ test.mligo | 3 +++ 2 files changed, 10 insertions(+), 12 deletions(-) create mode 100644 test.mligo diff --git a/src/passes/2-simplify/cameligo.ml b/src/passes/2-simplify/cameligo.ml index 222dee09f..910da246f 100644 --- a/src/passes/2-simplify/cameligo.ml +++ b/src/passes/2-simplify/cameligo.ml @@ -812,8 +812,8 @@ and simpl_declaration : Raw.declaration -> declaration Location.wrap list result ok (var , tl) in let%bind lhs_type' = bind_map_option (fun x -> simpl_type_expression (snd x)) lhs_type in - let let_rhs = match args with - | [] -> let_rhs + let%bind let_rhs,lhs_type = match args with + | [] -> ok (let_rhs, lhs_type') | param1::others -> let fun_ = { kwd_fun = Region.ghost; @@ -822,18 +822,13 @@ and simpl_declaration : Raw.declaration -> declaration Location.wrap list result arrow = Region.ghost; body = let_rhs } in - Raw.EFun {region=Region.ghost ; value=fun_} - in - let f_args = (match let_rhs with - | Raw.EFun f -> nseq_to_list f.value.binders - | _ -> [] - ) + let f_args = nseq_to_list (param1,others) in + let%bind ty = bind_map_list typed_pattern_to_typed_vars f_args in + let aux acc ty = Option.map (t_function (snd ty)) acc in + ok (Raw.EFun {region=Region.ghost ; value=fun_},List.fold_right' aux lhs_type' ty) in let%bind rhs' = simpl_expression let_rhs in - let%bind ty = bind_map_list typed_pattern_to_typed_vars f_args in - let aux acc ty = Option.map (t_function (snd ty)) acc in - let func_type = List.fold_right' aux lhs_type' ty in - ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , func_type , inline, rhs'))] + ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , lhs_type , inline, rhs'))] ) and simpl_cases : type a . (Raw.pattern * a) list -> (a, unit) matching_content result = diff --git a/test.mligo b/test.mligo new file mode 100644 index 000000000..5ad65e3f3 --- /dev/null +++ b/test.mligo @@ -0,0 +1,3 @@ +let f : int = fun (x, y : int*int) -> x + y +let g (x, y : int * int) : int = f (x, y) + From dfb1e1ebef90154ec88acd08d1b1ac1458374e42 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Tue, 3 Mar 2020 16:37:46 +0100 Subject: [PATCH 7/9] add negative test --- src/bin/expect_tests/typer_error_tests.ml | 15 ++++++++++++++- ...on.mligo => error_function_annotation_1.mligo} | 0 .../negative/error_function_annotation_2.mligo | 1 - 3 files changed, 14 insertions(+), 2 deletions(-) rename src/test/contracts/negative/{error_function_annotation.mligo => error_function_annotation_1.mligo} (100%) rename test.mligo => src/test/contracts/negative/error_function_annotation_2.mligo (98%) diff --git a/src/bin/expect_tests/typer_error_tests.ml b/src/bin/expect_tests/typer_error_tests.ml index 32eb559d7..a9b5ce6f2 100644 --- a/src/bin/expect_tests/typer_error_tests.ml +++ b/src/bin/expect_tests/typer_error_tests.ml @@ -1,11 +1,24 @@ open Cli_expect let%expect_test _ = - run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_annotation.mligo"; "main"]; + run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_annotation_1.mligo"; "main"]; [%expect {| ligo: in file "", line 0, characters 0-0. different type constructors: Expected these two constant type constructors to be the same, but they're different {"a":"unit","b":"int"} + If you're not sure how to fix this error, you can + do one of the following: + + * Visit our documentation: https://ligolang.org/docs/intro/what-and-why/ + * 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' |}]; + + run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_annotation_2.mligo"; "f"]; + [%expect {| + ligo: in file "error_function_annotation_2.mligo", line 1, characters 14-43. different kinds: {"a":"int","b":"( int * int ) -> int"} + + If you're not sure how to fix this error, you can do one of the following: diff --git a/src/test/contracts/negative/error_function_annotation.mligo b/src/test/contracts/negative/error_function_annotation_1.mligo similarity index 100% rename from src/test/contracts/negative/error_function_annotation.mligo rename to src/test/contracts/negative/error_function_annotation_1.mligo diff --git a/test.mligo b/src/test/contracts/negative/error_function_annotation_2.mligo similarity index 98% rename from test.mligo rename to src/test/contracts/negative/error_function_annotation_2.mligo index 5ad65e3f3..a65a8d47e 100644 --- a/test.mligo +++ b/src/test/contracts/negative/error_function_annotation_2.mligo @@ -1,3 +1,2 @@ let f : int = fun (x, y : int*int) -> x + y let g (x, y : int * int) : int = f (x, y) - From c23827e8de9c3405111c7460e5d38f7119401cc0 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Tue, 3 Mar 2020 17:45:59 +0100 Subject: [PATCH 8/9] new negative test --- src/bin/expect_tests/typer_error_tests.ml | 13 +++++++++++++ .../negative/error_function_annotation_3.mligo | 9 +++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/test/contracts/negative/error_function_annotation_3.mligo diff --git a/src/bin/expect_tests/typer_error_tests.ml b/src/bin/expect_tests/typer_error_tests.ml index a9b5ce6f2..48d53bcbd 100644 --- a/src/bin/expect_tests/typer_error_tests.ml +++ b/src/bin/expect_tests/typer_error_tests.ml @@ -19,6 +19,19 @@ let%expect_test _ = ligo: in file "error_function_annotation_2.mligo", line 1, characters 14-43. different kinds: {"a":"int","b":"( int * int ) -> int"} + If you're not sure how to fix this error, you can + do one of the following: + + * Visit our documentation: https://ligolang.org/docs/intro/what-and-why/ + * 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' |}]; + + run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_annotation_3.mligo"; "f"]; + [%expect {| + ligo: in file "", line 0, characters 0-0. different kinds: {"a":"( (TO_list(operation)) * sum[Add -> int , Sub -> int] )","b":"sum[Add -> int , Sub -> int]"} + + If you're not sure how to fix this error, you can do one of the following: diff --git a/src/test/contracts/negative/error_function_annotation_3.mligo b/src/test/contracts/negative/error_function_annotation_3.mligo new file mode 100644 index 000000000..28d1e0e42 --- /dev/null +++ b/src/test/contracts/negative/error_function_annotation_3.mligo @@ -0,0 +1,9 @@ +type op = + | Add of int + | Sub of int + + +let main (p,s : int * op) : (operation list) * op = + match s with + | Add si -> Add si + | Sub si -> Sub si From b7e65764ddb99289e1ab07ac160f7f4cd6715b13 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Wed, 4 Mar 2020 00:10:52 +0100 Subject: [PATCH 9/9] dune promote --- src/bin/expect_tests/contract_tests.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index 0706ceda8..1e7b64778 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -1149,7 +1149,7 @@ let%expect_test _ = let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_toplevel.mligo" ; "main" ] ; [%expect {| - ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8. No free variable allowed in this lambda: variable 'store' {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * string ):Some(( nat * string ))) : None return let rhs#752 = #P in let p = rhs#752.0 in let s = rhs#752.1 in ( list[] : (TO_list(operation)) , store ) , NONE() : (TO_option(key_hash)) , 300000000mutez , \"un\")","location":"in file \"create_contract_toplevel.mligo\", line 4, character 35 to line 8, character 8"} + ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8. No free variable allowed in this lambda: variable 'store' {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * string ):Some(( nat * string ))) : None return let rhs#756 = #P in let p = rhs#756.0 in let s = rhs#756.1 in ( list[] : (TO_list(operation)) , store ) , NONE() : (TO_option(key_hash)) , 300000000mutez , \"un\")","location":"in file \"create_contract_toplevel.mligo\", line 4, character 35 to line 8, character 8"} If you're not sure how to fix this error, you can @@ -1162,7 +1162,7 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_var.mligo" ; "main" ] ; [%expect {| - ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5. No free variable allowed in this lambda: variable 'a' {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * int ):Some(( nat * int ))) : None return let rhs#755 = #P in let p = rhs#755.0 in let s = rhs#755.1 in ( list[] : (TO_list(operation)) , a ) , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_var.mligo\", line 6, character 35 to line 10, character 5"} + ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5. No free variable allowed in this lambda: variable 'a' {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * int ):Some(( nat * int ))) : None return let rhs#759 = #P in let p = rhs#759.0 in let s = rhs#759.1 in ( list[] : (TO_list(operation)) , a ) , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_var.mligo\", line 6, character 35 to line 10, character 5"} If you're not sure how to fix this error, you can @@ -1175,7 +1175,7 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_no_inline.mligo" ; "main" ] ; [%expect {| - ligo: in file "create_contract_no_inline.mligo", line 9, characters 19-89. CREATE_CONTRACT first argument must be inlined: contract code can be inlined using a lambda {"expression":"CREATE_CONTRACT(dummy_contract , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_no_inline.mligo\", line 9, characters 19-89"} + ligo: unbound type variable: {"variable":"return","in":"- E[foo -> int]\tT[] ]","did_you_mean":"no suggestion"} If you're not sure how to fix this error, you can