Merge branch '125-invalid-address-literals-are-rejected-with-a-catch-all-contract-did-not-typecheck' into 'dev'
Resolve "Invalid address literals are rejected with a catch-all "contract did not typecheck"" Closes #125 See merge request ligolang/ligo!294
This commit is contained in:
commit
78276f451e
@ -932,3 +932,7 @@ let%expect_test _ =
|
||||
let%expect_test _ =
|
||||
run_ligo_bad [ "run-function" ; contract "failwith.ligo" ; "failer" ; "1" ] ;
|
||||
[%expect {| ligo: Execution failed: {"value":"some_string","type":"string"} |}]
|
||||
|
||||
let%expect_test _ =
|
||||
run_ligo_bad [ "compile-contract" ; contract "bad_address_format.religo" ; "main" ] ;
|
||||
[%expect {| ligo: in file "bad_address_format.religo", line 2, characters 25-47. Badly formatted address "KT1badaddr": {"location":"in file \"bad_address_format.religo\", line 2, characters 25-47"} |}]
|
||||
|
@ -4,6 +4,7 @@
|
||||
(libraries
|
||||
simple-utils
|
||||
ast_simplified
|
||||
proto-alpha-utils
|
||||
)
|
||||
(preprocess
|
||||
(pps ppx_let bisect_ppx --conditional)
|
||||
|
@ -1,9 +1,28 @@
|
||||
open Ast_simplified
|
||||
open Trace
|
||||
open Proto_alpha_utils
|
||||
|
||||
module Errors = struct
|
||||
let bad_literal_address s_addr loc () =
|
||||
let title = (thunk ("Badly formatted address \""^s_addr^"\"")) in
|
||||
let message () = "" in
|
||||
let data = [
|
||||
("location" , fun () -> Format.asprintf "%a" Location.pp loc)
|
||||
] in
|
||||
error ~data title message ()
|
||||
end
|
||||
open Errors
|
||||
|
||||
let peephole_expression : expression -> expression result = fun e ->
|
||||
let return expression = ok { e with expression } in
|
||||
match e.expression with
|
||||
| E_literal (Literal_address s) as l -> (
|
||||
let open Memory_proto_alpha in
|
||||
let%bind (_contract:Protocol.Alpha_context.Contract.t) =
|
||||
Trace.trace_alpha_tzresult (bad_literal_address s e.location) @@
|
||||
Protocol.Alpha_context.Contract.of_b58check s in
|
||||
return l
|
||||
)
|
||||
| E_constant (C_BIG_MAP_LITERAL , lst) -> (
|
||||
let%bind elt =
|
||||
trace_option (simple_error "big_map literal expects a single parameter") @@
|
||||
|
3
src/test/contracts/bad_address_format.religo
Normal file
3
src/test/contracts/bad_address_format.religo
Normal file
@ -0,0 +1,3 @@
|
||||
let main = (parameter: int, storage: address) => {
|
||||
([]:list(operation), "KT1badaddr" : address);
|
||||
};
|
Loading…
Reference in New Issue
Block a user