Allow to failwith an int (or nat)
This commit is contained in:
parent
16ecd532b9
commit
8066e4df26
@ -963,16 +963,6 @@ let%expect_test _ =
|
|||||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||||
* Check the changelog by running 'ligo changelog' |}]
|
* Check the changelog by running 'ligo changelog' |}]
|
||||||
|
|
||||||
let%expect_test _ =
|
|
||||||
run_ligo_good [ "run-function" ; contract "failwith.ligo" ; "failer" ; "1" ] ;
|
|
||||||
[%expect {|
|
|
||||||
failwith("some_string") |}]
|
|
||||||
|
|
||||||
let%expect_test _ =
|
|
||||||
run_ligo_good [ "run-function" ; contract "failwith.ligo" ; "failer" ; "1" ; "--format=json" ] ;
|
|
||||||
[%expect {|
|
|
||||||
{"status":"ok","content":"failwith(\"some_string\")"} |}]
|
|
||||||
|
|
||||||
let%expect_test _ =
|
let%expect_test _ =
|
||||||
run_ligo_bad [ "compile-contract" ; contract "bad_address_format.religo" ; "main" ] ;
|
run_ligo_bad [ "compile-contract" ; contract "bad_address_format.religo" ; "main" ] ;
|
||||||
[%expect {|
|
[%expect {|
|
||||||
@ -1084,7 +1074,7 @@ let%expect_test _ =
|
|||||||
let%expect_test _ =
|
let%expect_test _ =
|
||||||
run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_toplevel.mligo" ; "main" ] ;
|
run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_toplevel.mligo" ; "main" ] ;
|
||||||
[%expect {|
|
[%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:Some(( nat * string ))) : None return\n let rhs#727 = #P in\n let p = rhs#727.0 in\n let s = rhs#727.1 in\n ( LIST_EMPTY() : (type_operator: list(operation)) , store ) ,\n NONE() : (type_operator: option(key_hash)) ,\n 300000000mutez ,\n \"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:Some(( nat * string ))) : None return\n let rhs#693 = #P in\n let p = rhs#693.0 in\n let s = rhs#693.1 in\n ( LIST_EMPTY() : (type_operator: list(operation)) , store ) ,\n NONE() : (type_operator: option(key_hash)) ,\n 300000000mutez ,\n \"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
|
If you're not sure how to fix this error, you can
|
||||||
@ -1097,7 +1087,7 @@ ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8,
|
|||||||
|
|
||||||
run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_var.mligo" ; "main" ] ;
|
run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_var.mligo" ; "main" ] ;
|
||||||
[%expect {|
|
[%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:Some(( nat * int ))) : None return\n let rhs#730 = #P in\n let p = rhs#730.0 in\n let s = rhs#730.1 in\n ( LIST_EMPTY() : (type_operator: list(operation)) , a ) ,\n NONE() : (type_operator: option(key_hash)) ,\n 300000000mutez ,\n 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:Some(( nat * int ))) : None return\n let rhs#696 = #P in\n let p = rhs#696.0 in\n let s = rhs#696.1 in\n ( LIST_EMPTY() : (type_operator: list(operation)) , a ) ,\n NONE() : (type_operator: option(key_hash)) ,\n 300000000mutez ,\n 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
|
If you're not sure how to fix this error, you can
|
||||||
|
@ -8,11 +8,11 @@ let bad_contract basename =
|
|||||||
let%expect_test _ =
|
let%expect_test _ =
|
||||||
run_ligo_good [ "run-function" ; contract "failwith.ligo" ; "failer" ; "1" ] ;
|
run_ligo_good [ "run-function" ; contract "failwith.ligo" ; "failer" ; "1" ] ;
|
||||||
[%expect {|
|
[%expect {|
|
||||||
failwith("some_string") |}];
|
failwith(42) |}];
|
||||||
|
|
||||||
run_ligo_good [ "run-function" ; contract "failwith.ligo" ; "failer" ; "1" ; "--format=json" ] ;
|
run_ligo_good [ "run-function" ; contract "failwith.ligo" ; "failer" ; "1" ; "--format=json" ] ;
|
||||||
[%expect {|
|
[%expect {|
|
||||||
{"status":"ok","content":"failwith(\"some_string\")"} |}];
|
{"status":"ok","content":"failwith(42)"} |}];
|
||||||
|
|
||||||
|
|
||||||
run_ligo_good [ "dry-run" ; contract "subtle_nontail_fail.mligo" ; "main" ; "()" ; "()" ] ;
|
run_ligo_good [ "dry-run" ; contract "subtle_nontail_fail.mligo" ; "main" ; "()" ; "()" ] ;
|
||||||
|
@ -189,4 +189,17 @@ let%expect_test _ =
|
|||||||
* Visit our documentation: https://ligolang.org/docs/intro/introduction
|
* Visit our documentation: https://ligolang.org/docs/intro/introduction
|
||||||
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
* Ask a question on our Discord: https://discord.gg/9rhYaEt
|
||||||
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
|
||||||
* Check the changelog by running 'ligo changelog' |}];
|
* Check the changelog by running 'ligo changelog' |}]
|
||||||
|
|
||||||
|
let%expect_test _ =
|
||||||
|
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/failwith_wrong_type.ligo" ; "main" ] ;
|
||||||
|
[%expect {|
|
||||||
|
ligo: in file "failwith_wrong_type.ligo", line 2, characters 19-46. Failwith with disallowed type: Expected arguments with one of the following combinations of types: failwith(string) or failwith(nat) or failwith(int) but got this combination instead: failwith((type_operator: list(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/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' |}]
|
||||||
|
@ -702,9 +702,21 @@ module Typer = struct
|
|||||||
[i ; j ; s] ()
|
[i ; j ; s] ()
|
||||||
|
|
||||||
let failwith_ = typer_1_opt "FAILWITH" @@ fun t opt ->
|
let failwith_ = typer_1_opt "FAILWITH" @@ fun t opt ->
|
||||||
let%bind () =
|
let%bind _ =
|
||||||
Assert.assert_true @@
|
if eq_1 t (t_string ())
|
||||||
(is_t_string t) in
|
then ok ()
|
||||||
|
else if eq_1 t (t_nat ())
|
||||||
|
then ok ()
|
||||||
|
else if eq_1 t (t_int ())
|
||||||
|
then ok ()
|
||||||
|
else
|
||||||
|
fail @@ Operator_errors.typeclass_error "Failwith with disallowed type" "failwith"
|
||||||
|
[
|
||||||
|
[t_string()] ;
|
||||||
|
[t_nat()] ;
|
||||||
|
[t_int()] ;
|
||||||
|
]
|
||||||
|
[t] () in
|
||||||
let default = t_unit () in
|
let default = t_unit () in
|
||||||
ok @@ Simple_utils.Option.unopt ~default opt
|
ok @@ Simple_utils.Option.unopt ~default opt
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ function foobar (const i : int) : int is
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
case p of
|
case p of
|
||||||
Zero (n) -> failwith ("wooo")
|
Zero (n) -> failwith(42n)
|
||||||
| Pos (n) -> skip
|
| Pos (n) -> skip
|
||||||
end
|
end
|
||||||
} with
|
} with
|
||||||
@ -39,5 +39,5 @@ function foobar (const i : int) : int is
|
|||||||
end
|
end
|
||||||
|
|
||||||
function failer (const p : int) : int is block {
|
function failer (const p : int) : int is block {
|
||||||
if p = 1 then failwith ("some_string") else skip
|
if p = 1 then failwith (42) else skip
|
||||||
} with p
|
} with p
|
||||||
|
2
src/test/contracts/negative/failwith_wrong_type.ligo
Normal file
2
src/test/contracts/negative/failwith_wrong_type.ligo
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
const bad : unit = failwith((nil : list(int)))
|
Loading…
Reference in New Issue
Block a user