Merge branch 'gardening/improve_on_error_formatting' into 'dev'

bunch of fixes to the PPs

See merge request ligolang/ligo!705
This commit is contained in:
Rémi Lesenechal 2020-07-02 18:10:56 +00:00
commit 43b70361bc
6 changed files with 52 additions and 60 deletions

View File

@ -31,12 +31,9 @@ let%expect_test _ =
[%expect {| [%expect {|
ligo: error ligo: error
Provided storage type does not match contract storage type Provided storage type does not match contract storage type
Bad types: expected record[card_patterns -> (type_operator: Map (nat,record[coefficient -> mutez , quantity -> nat])) , Bad types:
cards -> (type_operator: Map (nat,record[card_owner -> address , card_pattern -> nat])) , expected record[card_patterns -> (type_operator: Map (nat,record[coefficient -> mutez , quantity -> nat])) , cards -> (type_operator: Map (nat,record[card_owner -> address , card_pattern -> nat])) , next_id -> nat]
next_id -> nat] got sum[Buy_single -> record[card_to_buy -> nat] , got sum[Buy_single -> record[card_to_buy -> nat] , Sell_single -> record[card_to_sell -> nat] , Transfer_single -> record[card_to_transfer -> nat , destination -> address]]
Sell_single -> record[card_to_sell -> nat] ,
Transfer_single -> record[card_to_transfer -> nat ,
destination -> address]]
If you're not sure how to fix this error, you can do one of the following: If you're not sure how to fix this error, you can do one of the following:
@ -50,12 +47,9 @@ let%expect_test _ =
[%expect {| [%expect {|
ligo: error ligo: error
Provided parameter type does not match contract parameter type Provided parameter type does not match contract parameter type
Bad types: expected sum[Buy_single -> record[card_to_buy -> nat] , Bad types:
Sell_single -> record[card_to_sell -> nat] , expected sum[Buy_single -> record[card_to_buy -> nat] , Sell_single -> record[card_to_sell -> nat] , Transfer_single -> record[card_to_transfer -> nat , destination -> address]]
Transfer_single -> record[card_to_transfer -> nat , got record[card_patterns -> (type_operator: Map (nat,record[coefficient -> mutez , quantity -> nat])) , cards -> (type_operator: Map (nat,record[card_owner -> address , card_pattern -> nat])) , next_id -> nat]
destination -> address]] got record[card_patterns -> (type_operator: Map (nat,record[coefficient -> mutez , quantity -> nat])) ,
cards -> (type_operator: Map (nat,record[card_owner -> address , card_pattern -> nat])) ,
next_id -> nat]
If you're not sure how to fix this error, you can do one of the following: If you're not sure how to fix this error, you can do one of the following:
@ -1467,7 +1461,7 @@ 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: error ligo: error
in file "create_contract_toplevel.mligo", line 3, characters 0-3 in file "create_contract_toplevel.mligo", line 3, characters 4-8
Constant declaration 'main' Constant declaration 'main'
in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8 in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8
Free variable 'store' is not allowed in CREATE_CONTRACT lambda Free variable 'store' is not allowed in CREATE_CONTRACT lambda
@ -1483,7 +1477,7 @@ If you're not sure how to fix this error, you can do one of the following:
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: error ligo: error
in file "create_contract_var.mligo", line 5, characters 0-3 in file "create_contract_var.mligo", line 5, characters 4-8
Constant declaration 'main' Constant declaration 'main'
in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5 in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5
Free variable 'a' is not allowed in CREATE_CONTRACT lambda Free variable 'a' is not allowed in CREATE_CONTRACT lambda

View File

@ -9,7 +9,7 @@ let%expect_test _ =
run_ligo_bad [ "interpret" ; "--init-file="^(bad_contract "michelson_converter_no_annotation.mligo") ; "l4"] ; run_ligo_bad [ "interpret" ; "--init-file="^(bad_contract "michelson_converter_no_annotation.mligo") ; "l4"] ;
[%expect {| [%expect {|
ligo: error ligo: error
in file "michelson_converter_no_annotation.mligo", line 4, characters 9-39 in file "michelson_converter_no_annotation.mligo", line 4, characters 4-6
Constant declaration 'l4' Constant declaration 'l4'
Can't retrieve type declaration order in the converted record, you need to annotate it Can't retrieve type declaration order in the converted record, you need to annotate it
@ -24,7 +24,7 @@ let%expect_test _ =
run_ligo_bad [ "interpret" ; "--init-file="^(bad_contract "michelson_converter_short_record.mligo") ; "l1"] ; run_ligo_bad [ "interpret" ; "--init-file="^(bad_contract "michelson_converter_short_record.mligo") ; "l1"] ;
[%expect {| [%expect {|
ligo: error ligo: error
in file "michelson_converter_short_record.mligo", line 4, characters 9-44 in file "michelson_converter_short_record.mligo", line 4, characters 4-6
Constant declaration 'l1' Constant declaration 'l1'
in file "michelson_converter_short_record.mligo", line 1, characters 10-23 in file "michelson_converter_short_record.mligo", line 1, characters 10-23
Converted record must have at least two elements Converted record must have at least two elements

View File

@ -30,7 +30,7 @@ let%expect_test _ =
run_ligo_bad [ "compile-contract" ; bad_contract "bad_michelson_or.mligo" ; "main" ] ; run_ligo_bad [ "compile-contract" ; bad_contract "bad_michelson_or.mligo" ; "main" ] ;
[%expect {| [%expect {|
ligo: error ligo: error
in file "bad_michelson_or.mligo", line 5, characters 0-3 in file "bad_michelson_or.mligo", line 5, characters 4-8
Constant declaration 'main' Constant declaration 'main'
in file "bad_michelson_or.mligo", line 6, characters 12-27 in file "bad_michelson_or.mligo", line 6, characters 12-27
michelson_or contructor M_right must be annotated with a sum type michelson_or contructor M_right must be annotated with a sum type

View File

@ -4,7 +4,7 @@ let%expect_test _ =
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_annotation_1.mligo"; "main"]; run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_annotation_1.mligo"; "main"];
[%expect {| [%expect {|
ligo: error ligo: error
in file "error_function_annotation_1.mligo", line 1, characters 0-3 in file "error_function_annotation_1.mligo", line 1, characters 4-8
Constant declaration 'main' Constant declaration 'main'
Bad types: expected int -> unit got int -> int Bad types: expected int -> unit got int -> int
@ -19,7 +19,7 @@ let%expect_test _ =
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_annotation_2.mligo"; "f"]; run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_annotation_2.mligo"; "f"];
[%expect {| [%expect {|
ligo: error ligo: error
in file "error_function_annotation_2.mligo", line 1, characters 14-43 in file "error_function_annotation_2.mligo", line 1, characters 4-5
Constant declaration 'f' Constant declaration 'f'
Bad types: expected int got ( int * int ) -> int Bad types: expected int got ( int * int ) -> int
@ -34,14 +34,11 @@ let%expect_test _ =
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_annotation_3.mligo"; "f"]; run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_annotation_3.mligo"; "f"];
[%expect {| [%expect {|
ligo: error ligo: error
in file "error_function_annotation_3.mligo", line 6, characters 0-3 in file "error_function_annotation_3.mligo", line 6, characters 4-8
Constant declaration 'main' Constant declaration 'main'
Bad types: expected ( int * sum[Add -> int , Sub -> int] ) -> ( (type_operator: list(operation)) * Bad types:
sum[Add -> int , expected ( int * sum[Add -> int , Sub -> int] ) -> ( (type_operator: list(operation)) * sum[Add -> int , Sub -> int] )
Sub -> int] ) got ( int * got ( int * sum[Add -> int , Sub -> int] ) -> sum[Add -> int , Sub -> int]
sum[Add -> int ,
Sub -> int] ) -> sum[Add -> int ,
Sub -> int]
If you're not sure how to fix this error, you can do one of the following: If you're not sure how to fix this error, you can do one of the following:
@ -68,7 +65,7 @@ let%expect_test _ =
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_type.ligo" ; "main" ] ; run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_type.ligo" ; "main" ] ;
[%expect {| [%expect {|
ligo: error ligo: error
in file "error_type.ligo", line 3, characters 18-28 in file "error_type.ligo", line 3, characters 6-9
Constant declaration 'foo' Constant declaration 'foo'
Expected arguments with one of the following combinations of type: Expected arguments with one of the following combinations of type:
(nat , nat) or (int , int) or (mutez , mutez) or (nat , int) or (int , nat) or (timestamp , int) or (int , timestamp) (nat , nat) or (int , int) or (mutez , mutez) or (nat , int) or (int , nat) or (timestamp , int) or (int , timestamp)
@ -85,7 +82,7 @@ let%expect_test _ =
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_1.mligo" ; "main" ] ; run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_1.mligo" ; "main" ] ;
[%expect {| [%expect {|
ligo: error ligo: error
in file "error_typer_1.mligo", line 3, characters 19-27 in file "error_typer_1.mligo", line 3, characters 4-7
Constant declaration 'foo' Constant declaration 'foo'
Bad types: expected string got int Bad types: expected string got int
@ -100,9 +97,11 @@ let%expect_test _ =
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_2.mligo" ; "main" ] ; run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_2.mligo" ; "main" ] ;
[%expect {| [%expect {|
ligo: error ligo: error
in file "error_typer_2.mligo", line 3, characters 24-39 in file "error_typer_2.mligo", line 3, characters 4-7
Constant declaration 'foo' Constant declaration 'foo'
Bad types: expected (type_operator: list(string)) got (type_operator: option(int)) Bad types:
expected (type_operator: list(string))
got (type_operator: option(int))
If you're not sure how to fix this error, you can do one of the following: If you're not sure how to fix this error, you can do one of the following:
@ -115,10 +114,11 @@ let%expect_test _ =
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_3.mligo" ; "main" ] ; run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_3.mligo" ; "main" ] ;
[%expect {| [%expect {|
ligo: error ligo: error
in file "error_typer_3.mligo", line 3, characters 34-53 in file "error_typer_3.mligo", line 3, characters 4-7
Constant declaration 'foo' Constant declaration 'foo'
Bad types: expected ( int * string * sum[false -> unit , true -> unit] ) got ( int * Bad types:
string ) expected ( int * string * sum[false -> unit , true -> unit] )
got ( int * string )
If you're not sure how to fix this error, you can do one of the following: If you're not sure how to fix this error, you can do one of the following:
@ -131,14 +131,11 @@ let%expect_test _ =
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_4.mligo" ; "main" ] ; run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_4.mligo" ; "main" ] ;
[%expect {| [%expect {|
ligo: error ligo: error
in file "error_typer_4.mligo", line 4, characters 17-56 in file "error_typer_4.mligo", line 4, characters 4-7
Constant declaration 'foo' Constant declaration 'foo'
Bad types: expected record[a -> int , Bad types:
c -> sum[false -> unit , true -> unit] , expected record[a -> int , c -> sum[false -> unit , true -> unit] , d -> string]
d -> string] got record[a -> int , got record[a -> int , b -> string , c -> sum[false -> unit , true -> unit]]
b -> string ,
c -> sum[false -> unit ,
true -> unit]]
If you're not sure how to fix this error, you can do one of the following: If you're not sure how to fix this error, you can do one of the following:
@ -166,9 +163,11 @@ let%expect_test _ =
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_6.mligo" ; "main" ] ; run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_6.mligo" ; "main" ] ;
[%expect {| [%expect {|
ligo: error ligo: error
in file "error_typer_6.mligo", line 1, characters 30-64 in file "error_typer_6.mligo", line 1, characters 4-7
Constant declaration 'foo' Constant declaration 'foo'
Bad types: expected (type_operator: Map (int,string)) got (type_operator: Map (int,sum[false -> unit , true -> unit])) Bad types:
expected (type_operator: Map (int,string))
got (type_operator: Map (int,sum[false -> unit , true -> unit]))
If you're not sure how to fix this error, you can do one of the following: If you're not sure how to fix this error, you can do one of the following:
@ -181,12 +180,11 @@ let%expect_test _ =
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_7.mligo" ; "main" ] ; run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_7.mligo" ; "main" ] ;
[%expect {| [%expect {|
ligo: error ligo: error
in file "error_typer_7.mligo", line 4, characters 17-56 in file "error_typer_7.mligo", line 4, characters 4-7
Constant declaration 'foo' Constant declaration 'foo'
Bad types: expected record[a -> int , b -> string] got record[a -> int , Bad types:
b -> string , expected record[a -> int , b -> string]
c -> sum[false -> unit , got record[a -> int , b -> string , c -> sum[false -> unit , true -> unit]]
true -> unit]]
If you're not sure how to fix this error, you can do one of the following: If you're not sure how to fix this error, you can do one of the following:
@ -199,12 +197,10 @@ let%expect_test _ =
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/id.mligo" ; "main" ] ; run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/id.mligo" ; "main" ] ;
[%expect {| [%expect {|
ligo: error ligo: error
in file "id.mligo", line 28, characters 0-3 in file "id.mligo", line 28, characters 4-7
Constant declaration 'buy' Constant declaration 'buy'
in file "id.mligo", line 3, character 18 to line 7, character 1 in file "id.mligo", line 3, character 18 to line 7, character 1
Expected an option but got record[controller -> address , Expected an option but got record[controller -> address , owner -> address , profile -> bytes]
owner -> address ,
profile -> bytes]
If you're not sure how to fix this error, you can do one of the following: If you're not sure how to fix this error, you can do one of the following:
@ -240,7 +236,7 @@ let%expect_test _ =
run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/failwith_wrong_type.ligo" ; "main" ] ; run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/failwith_wrong_type.ligo" ; "main" ] ;
[%expect {| [%expect {|
ligo: error ligo: error
in file "failwith_wrong_type.ligo", line 2, characters 19-46 in file "failwith_wrong_type.ligo", line 2, characters 6-9
Constant declaration 'bad' Constant declaration 'bad'
Expected arguments with one of the following combinations of type: Expected arguments with one of the following combinations of type:
(string) or (nat) or (int) (string) or (nat) or (int)

View File

@ -258,10 +258,10 @@ let rec error_ppformat : display_format:string display_format ->
Format.fprintf f Format.fprintf f
"%a" "%a"
(error_ppformat ~display_format) err (error_ppformat ~display_format) err
| `Typer_constant_declaration_tracer (name,ae,_,err) -> | `Typer_constant_declaration_tracer (name,_ae,_,err) ->
Format.fprintf f Format.fprintf f
"@[<hv>%a@ Constant declaration '%a'@ %a@]" "@[<hv>%a@ Constant declaration '%a'@ %a@]"
Location.pp ae.location Location.pp name.location
Ast_core.PP.expression_variable name Ast_core.PP.expression_variable name
(error_ppformat ~display_format) err (error_ppformat ~display_format) err
| `Typer_match_error (expected,actual,loc) -> | `Typer_match_error (expected,actual,loc) ->
@ -301,7 +301,7 @@ let rec error_ppformat : display_format:string display_format ->
error_ppformat ~display_format f err error_ppformat ~display_format f err
| `Typer_assert_equal (expected,actual) -> | `Typer_assert_equal (expected,actual) ->
Format.fprintf f Format.fprintf f
"@[<h>Bad types:@ expected %a@ got %a@]" "@[<hv>Bad types:@ expected %a@ got %a@]"
Ast_typed.PP.type_expression expected Ast_typed.PP.type_expression expected
Ast_typed.PP.type_expression actual Ast_typed.PP.type_expression actual
| `Typer_corner_case desc -> | `Typer_corner_case desc ->
@ -716,13 +716,15 @@ let rec error_jsonformat : typer_error -> J.t = fun a ->
json_error ~stage ~content json_error ~stage ~content
| `Typer_constant_declaration_tracer (name,ae,Some t,err) -> | `Typer_constant_declaration_tracer (name,ae,Some t,err) ->
let message = `String "Typing constant declaration" in let message = `String "Typing constant declaration" in
let loc = `String (Format.asprintf "%a" Location.pp ae.location) in let value = `String (Format.asprintf "%a" Ast_core.PP.expression ae) in
let loc = `String (Format.asprintf "%a" Location.pp name.location) in
let name = `String (Format.asprintf "%a" Ast_core.PP.expression_variable name) in let name = `String (Format.asprintf "%a" Ast_core.PP.expression_variable name) in
let expected = `String (Format.asprintf "%a" Ast_typed.PP.type_expression t) in let expected = `String (Format.asprintf "%a" Ast_typed.PP.type_expression t) in
let content = `Assoc [ let content = `Assoc [
("message", message); ("message", message);
("location", loc); ("location", loc);
("name", name); ("name", name);
("value", value);
("expected", expected); ("expected", expected);
("children", error_jsonformat err); ("children", error_jsonformat err);
] in ] in

View File

@ -58,8 +58,8 @@ let tuple_or_record_sep_t value format_record sep_record format_tuple sep_tuple
let list_sep_d x = list_sep x (tag " ,@ ") let list_sep_d x = list_sep x (tag " ,@ ")
let cmap_sep_d x = cmap_sep x (tag " ,@ ") let cmap_sep_d x = cmap_sep x (tag " ,@ ")
let tuple_or_record_sep_expr value = tuple_or_record_sep value "@[<hv 7>record[%a]@]" " ,@ " "@[<hv 2>( %a )@]" " ,@ " let tuple_or_record_sep_expr value = tuple_or_record_sep value "@[<h>record[%a]@]" " ,@ " "@[<h>( %a )@]" " ,@ "
let tuple_or_record_sep_type value = tuple_or_record_sep_t value "@[<hv 7>record[%a]@]" " ,@ " "@[<hv 2>( %a )@]" " *@ " let tuple_or_record_sep_type value = tuple_or_record_sep_t value "@[<h>record[%a]@]" " ,@ " "@[<h>( %a )@]" " *@ "
let constant ppf : constant' -> unit = function let constant ppf : constant' -> unit = function
| C_INT -> fprintf ppf "INT" | C_INT -> fprintf ppf "INT"
@ -228,9 +228,9 @@ let rec type_expression' :
-> unit = -> unit =
fun f ppf te -> fun f ppf te ->
match te.type_content with match te.type_content with
| T_sum m -> fprintf ppf "@[<hv 4>sum[%a]@]" (cmap_sep_d f) (List.map (fun (c,{ctor_type;_}) -> (c,ctor_type)) (CMap.to_kv_list m)) | T_sum m -> fprintf ppf "@[<h>sum[%a]@]" (cmap_sep_d f) (List.map (fun (c,{ctor_type;_}) -> (c,ctor_type)) (CMap.to_kv_list m))
| T_record m -> fprintf ppf "%a" (tuple_or_record_sep_type f) m | T_record m -> fprintf ppf "%a" (tuple_or_record_sep_type f) m
| T_arrow a -> fprintf ppf "%a -> %a" f a.type1 f a.type2 | T_arrow a -> fprintf ppf "@[<h>%a ->@ %a@]" f a.type1 f a.type2
| T_variable tv -> type_variable ppf tv | T_variable tv -> type_variable ppf tv
| T_constant tc -> type_constant ppf tc | T_constant tc -> type_constant ppf tc
| T_operator to_ -> type_operator f ppf to_ | T_operator to_ -> type_operator f ppf to_