diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index facee666d..795e554ea 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -1144,4 +1144,51 @@ 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' |}] + +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: 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"} + + + 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" ; 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: 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"} + + + 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_good [ "compile-contract" ; contract "create_contract.mligo" ; "main" ] ; + [%expect {| + { parameter string ; + storage string ; + code { PUSH string "un" ; + PUSH mutez 300000000 ; + NONE key_hash ; + CREATE_CONTRACT + { parameter nat ; + storage string ; + code { PUSH string "one" ; NIL operation ; PAIR ; DIP { DROP } } } ; + PAIR ; + DUP ; + CAR ; + NIL operation ; + SWAP ; + CONS ; + DIP { DIP { DUP } ; SWAP ; CDR } ; + PAIR ; + DIP { DROP 2 } } } |}] diff --git a/src/test/contracts/create_contract.mligo b/src/test/contracts/create_contract.mligo new file mode 100644 index 000000000..8c405102c --- /dev/null +++ b/src/test/contracts/create_contract.mligo @@ -0,0 +1,10 @@ +type return = operation list * string + +let main (action, store : string * string) : return = + let toto : operation * address = Tezos.create_contract + (fun (p, s : nat * string) -> (([] : operation list), "one")) + (None: key_hash option) + 300tz + "un" + in + ([toto.0], store) \ No newline at end of file diff --git a/src/test/contracts/negative/create_contract_toplevel.mligo b/src/test/contracts/negative/create_contract_toplevel.mligo new file mode 100644 index 000000000..051464c11 --- /dev/null +++ b/src/test/contracts/negative/create_contract_toplevel.mligo @@ -0,0 +1,10 @@ +type return = operation list * string + +let main (action, store : string * string) : return = + let toto : operation * address = Tezos.create_contract + (fun (p, s : nat * string) -> (([] : operation list), store)) + (None: key_hash option) + 300tz + "un" + in + ([toto.0], store) \ No newline at end of file diff --git a/src/test/contracts/negative/create_contract_var.mligo b/src/test/contracts/negative/create_contract_var.mligo new file mode 100644 index 000000000..9bd0a3ffb --- /dev/null +++ b/src/test/contracts/negative/create_contract_var.mligo @@ -0,0 +1,12 @@ +type return = operation list * string + +let a : int = 2 + +let main (action, store : string * string) : return = + let toto : operation * address = Tezos.create_contract + (fun (p, s : nat * int) -> (([] : operation list), a)) + (None: key_hash option) + 300tz + 1 + in + ([toto.0], store) \ No newline at end of file