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:
Rémi Lesenechal 2020-01-02 15:12:11 +00:00
commit 78276f451e
4 changed files with 28 additions and 1 deletions

View File

@ -932,3 +932,7 @@ let%expect_test _ =
let%expect_test _ = let%expect_test _ =
run_ligo_bad [ "run-function" ; contract "failwith.ligo" ; "failer" ; "1" ] ; run_ligo_bad [ "run-function" ; contract "failwith.ligo" ; "failer" ; "1" ] ;
[%expect {| ligo: Execution failed: {"value":"some_string","type":"string"} |}] [%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"} |}]

View File

@ -4,6 +4,7 @@
(libraries (libraries
simple-utils simple-utils
ast_simplified ast_simplified
proto-alpha-utils
) )
(preprocess (preprocess
(pps ppx_let bisect_ppx --conditional) (pps ppx_let bisect_ppx --conditional)

View File

@ -1,9 +1,28 @@
open Ast_simplified open Ast_simplified
open Trace 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 peephole_expression : expression -> expression result = fun e ->
let return expression = ok { e with expression } in let return expression = ok { e with expression } in
match e.expression with 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) -> ( | E_constant (C_BIG_MAP_LITERAL , lst) -> (
let%bind elt = let%bind elt =
trace_option (simple_error "big_map literal expects a single parameter") @@ trace_option (simple_error "big_map literal expects a single parameter") @@

View File

@ -0,0 +1,3 @@
let main = (parameter: int, storage: address) => {
([]:list(operation), "KT1badaddr" : address);
};