diff --git a/src/bin/expect_tests/typer_error_tests.ml b/src/bin/expect_tests/typer_error_tests.ml index e68d52d14..6ecae91e7 100644 --- a/src/bin/expect_tests/typer_error_tests.ml +++ b/src/bin/expect_tests/typer_error_tests.ml @@ -16,4 +16,10 @@ let%expect_test _ = run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_5.mligo" ; "main" ] ; [%expect {| ligo: unbound type variable: {"variable":"boolean","in":"- E[]\tT[] ]","did_you_mean":"bool"} |} ] ; + run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_6.mligo" ; "main" ] ; + [%expect {| ligo: in file "error_typer_6.mligo", line 1, characters 30-64. different type constructors: Expected these two constant type constructors to be the same, but they're different {"a":"string","b":"bool"} |} ] ; + + run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/error_typer_7.mligo" ; "main" ] ; + [%expect {| ligo: in file "error_typer_7.mligo", line 4, characters 17-56. records have different sizes: Expected these two types to be the same, but they're different (both are records, but with a different number of arguments) {"a":"record[b -> string , a -> int]","b":"record[c -> bool , b -> string , a -> int]"} |} ] ; + diff --git a/src/stages/ast_typed/misc.ml b/src/stages/ast_typed/misc.ml index 4303a6f1b..ebfd7ee27 100644 --- a/src/stages/ast_typed/misc.ml +++ b/src/stages/ast_typed/misc.ml @@ -56,7 +56,7 @@ module Errors = struct let different_types name a b () = let title () = name ^ " are different" in - let message () = "" in + let message () = "Expected these two types to be the same, but they're different" in let data = [ ("a" , fun () -> Format.asprintf "%a" PP.type_value a) ; ("b" , fun () -> Format.asprintf "%a" PP.type_value b ) @@ -321,7 +321,7 @@ let rec assert_type_value_eq (a, b: (type_value * type_value)) : unit result = m | TC_big_map (ka,va), TC_big_map (kb,vb) -> ok @@ ([ka;va] ,[kb;vb]) | _,_ -> fail @@ different_operators opa opb in - trace (different_types "constant sub-expression" a b) + trace (different_types "arguments to type operators" a b) @@ bind_list_iter (fun (a,b) -> assert_type_value_eq (a,b) )(List.combine lsta lstb) ) | T_operator _, _ -> fail @@ different_kinds a b diff --git a/src/test/contracts/negative/error_typer_6.mligo b/src/test/contracts/negative/error_typer_6.mligo new file mode 100644 index 000000000..d885cd036 --- /dev/null +++ b/src/test/contracts/negative/error_typer_6.mligo @@ -0,0 +1,3 @@ +let foo : (int, string) map = (Map.literal [] : (int, bool) map) +let main (p:int) (storage : int) = + (([] : operation list) , p) diff --git a/src/test/contracts/negative/error_typer_7.mligo b/src/test/contracts/negative/error_typer_7.mligo new file mode 100644 index 000000000..00243b095 --- /dev/null +++ b/src/test/contracts/negative/error_typer_7.mligo @@ -0,0 +1,7 @@ +type toto = { a : int ; b : string } +type tata = { a : int ; } + +let foo : tata = ({a = 1 ; b = "foo" ; c = true} : toto) + +let main (p:int) (storage : int) = + (([] : operation list) , p + foo.a)