diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index b27434981..d77df3a0c 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -31,12 +31,9 @@ let%expect_test _ = [%expect {| ligo: error Provided storage type does not match contract storage type - Bad types: 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] 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]] + Bad types: + 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] + 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]] 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 {| ligo: error Provided parameter type does not match contract parameter type - Bad types: 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]] 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] + Bad types: + 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]] + 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: @@ -1467,7 +1461,7 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_toplevel.mligo" ; "main" ] ; [%expect {| 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' 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 @@ -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" ] ; [%expect {| 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' 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 diff --git a/src/bin/expect_tests/michelson_converter.ml b/src/bin/expect_tests/michelson_converter.ml index b3a2a18c0..1cad63e45 100644 --- a/src/bin/expect_tests/michelson_converter.ml +++ b/src/bin/expect_tests/michelson_converter.ml @@ -9,7 +9,7 @@ let%expect_test _ = run_ligo_bad [ "interpret" ; "--init-file="^(bad_contract "michelson_converter_no_annotation.mligo") ; "l4"] ; [%expect {| 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' 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"] ; [%expect {| 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' in file "michelson_converter_short_record.mligo", line 1, characters 10-23 Converted record must have at least two elements diff --git a/src/bin/expect_tests/michelson_or_tests.ml b/src/bin/expect_tests/michelson_or_tests.ml index 92b7c9554..6fe517e04 100644 --- a/src/bin/expect_tests/michelson_or_tests.ml +++ b/src/bin/expect_tests/michelson_or_tests.ml @@ -30,7 +30,7 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "bad_michelson_or.mligo" ; "main" ] ; [%expect {| 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' in file "bad_michelson_or.mligo", line 6, characters 12-27 michelson_or contructor M_right must be annotated with a sum type diff --git a/src/bin/expect_tests/typer_error_tests.ml b/src/bin/expect_tests/typer_error_tests.ml index 0ce3bb456..4d5ea615b 100644 --- a/src/bin/expect_tests/typer_error_tests.ml +++ b/src/bin/expect_tests/typer_error_tests.ml @@ -4,7 +4,7 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_function_annotation_1.mligo"; "main"]; [%expect {| 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' 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"]; [%expect {| 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' 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"]; [%expect {| 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' - Bad types: expected ( int * sum[Add -> int , Sub -> int] ) -> ( (type_operator: list(operation)) * - sum[Add -> int , - Sub -> int] ) got ( int * - sum[Add -> int , - Sub -> int] ) -> sum[Add -> int , - Sub -> int] + Bad types: + expected ( int * sum[Add -> int , Sub -> int] ) -> ( (type_operator: list(operation)) * sum[Add -> int , Sub -> int] ) + got ( 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: @@ -68,7 +65,7 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_type.ligo" ; "main" ] ; [%expect {| 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' 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) @@ -85,7 +82,7 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_1.mligo" ; "main" ] ; [%expect {| 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' 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" ] ; [%expect {| 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' - 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: @@ -115,10 +114,11 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_3.mligo" ; "main" ] ; [%expect {| 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' - Bad types: expected ( int * string * sum[false -> unit , true -> unit] ) got ( int * - string ) + Bad types: + 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: @@ -131,14 +131,11 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_4.mligo" ; "main" ] ; [%expect {| 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' - Bad types: expected record[a -> int , - c -> sum[false -> unit , true -> unit] , - d -> string] got record[a -> int , - b -> string , - c -> sum[false -> unit , - true -> unit]] + Bad types: + expected record[a -> int , c -> sum[false -> unit , true -> unit] , d -> string] + got record[a -> int , 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: @@ -166,9 +163,11 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_6.mligo" ; "main" ] ; [%expect {| 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' - 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: @@ -181,12 +180,11 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_7.mligo" ; "main" ] ; [%expect {| 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' - Bad types: expected record[a -> int , b -> string] got record[a -> int , - b -> string , - c -> sum[false -> unit , - true -> unit]] + Bad types: + expected record[a -> int , b -> string] + got record[a -> int , 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: @@ -199,12 +197,10 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/id.mligo" ; "main" ] ; [%expect {| ligo: error - in file "id.mligo", line 28, characters 0-3 + in file "id.mligo", line 28, characters 4-7 Constant declaration 'buy' in file "id.mligo", line 3, character 18 to line 7, character 1 - Expected an option but got record[controller -> address , - owner -> address , - profile -> bytes] + Expected an option but got record[controller -> address , owner -> address , profile -> bytes] 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" ] ; [%expect {| 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' Expected arguments with one of the following combinations of type: (string) or (nat) or (int) diff --git a/src/passes/09-typing/08-typer-common/errors.ml b/src/passes/09-typing/08-typer-common/errors.ml index 4e09f3285..6fdd209cf 100644 --- a/src/passes/09-typing/08-typer-common/errors.ml +++ b/src/passes/09-typing/08-typer-common/errors.ml @@ -258,10 +258,10 @@ let rec error_ppformat : display_format:string display_format -> Format.fprintf f "%a" (error_ppformat ~display_format) err - | `Typer_constant_declaration_tracer (name,ae,_,err) -> + | `Typer_constant_declaration_tracer (name,_ae,_,err) -> Format.fprintf f "@[%a@ Constant declaration '%a'@ %a@]" - Location.pp ae.location + Location.pp name.location Ast_core.PP.expression_variable name (error_ppformat ~display_format) err | `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 | `Typer_assert_equal (expected,actual) -> Format.fprintf f - "@[Bad types:@ expected %a@ got %a@]" + "@[Bad types:@ expected %a@ got %a@]" Ast_typed.PP.type_expression expected Ast_typed.PP.type_expression actual | `Typer_corner_case desc -> @@ -716,13 +716,15 @@ let rec error_jsonformat : typer_error -> J.t = fun a -> json_error ~stage ~content | `Typer_constant_declaration_tracer (name,ae,Some t,err) -> 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 expected = `String (Format.asprintf "%a" Ast_typed.PP.type_expression t) in let content = `Assoc [ ("message", message); ("location", loc); ("name", name); + ("value", value); ("expected", expected); ("children", error_jsonformat err); ] in diff --git a/src/stages/5-ast_typed/PP.ml b/src/stages/5-ast_typed/PP.ml index 4dd7c4943..db15f311d 100644 --- a/src/stages/5-ast_typed/PP.ml +++ b/src/stages/5-ast_typed/PP.ml @@ -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 cmap_sep_d x = cmap_sep x (tag " ,@ ") -let tuple_or_record_sep_expr value = tuple_or_record_sep value "@[record[%a]@]" " ,@ " "@[( %a )@]" " ,@ " -let tuple_or_record_sep_type value = tuple_or_record_sep_t value "@[record[%a]@]" " ,@ " "@[( %a )@]" " *@ " +let tuple_or_record_sep_expr value = tuple_or_record_sep value "@[record[%a]@]" " ,@ " "@[( %a )@]" " ,@ " +let tuple_or_record_sep_type value = tuple_or_record_sep_t value "@[record[%a]@]" " ,@ " "@[( %a )@]" " *@ " let constant ppf : constant' -> unit = function | C_INT -> fprintf ppf "INT" @@ -228,9 +228,9 @@ let rec type_expression' : -> unit = fun f ppf te -> match te.type_content with - | T_sum m -> fprintf ppf "@[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 "@[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_arrow a -> fprintf ppf "%a -> %a" f a.type1 f a.type2 + | T_arrow a -> fprintf ppf "@[%a ->@ %a@]" f a.type1 f a.type2 | T_variable tv -> type_variable ppf tv | T_constant tc -> type_constant ppf tc | T_operator to_ -> type_operator f ppf to_