diff --git a/src/bin/expect_tests/typer_error_tests.ml b/src/bin/expect_tests/typer_error_tests.ml index 182b54235..0ce3bb456 100644 --- a/src/bin/expect_tests/typer_error_tests.ml +++ b/src/bin/expect_tests/typer_error_tests.ml @@ -253,3 +253,21 @@ let%expect_test _ = * Ask a question on our Discord: https://discord.gg/9rhYaEt * Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new * Check the changelog by running 'ligo changelog' |}] + +let%expect_test _ = + run_ligo_bad [ "compile-contract" ; "../../test/contracts/negative/compare_sum_types.ligo" ; "main" ] ; + [%expect {| + ligo: error + in file "compare_sum_types.ligo", line 3, characters 9-13 + Constant declaration 'main' + Those two types are not comparable: + - sum[Bar -> unit , Foo -> unit] + - sum[Bar -> unit , Foo -> unit] + + + If you're not sure how to fix this error, you can do one of the following: + + * Visit our documentation: https://ligolang.org/docs/intro/introduction + * Ask a question on our Discord: https://discord.gg/9rhYaEt + * Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new + * Check the changelog by running 'ligo changelog' |}] \ No newline at end of file diff --git a/src/passes/09-typing/08-typer-common/constant_typers.ml b/src/passes/09-typing/08-typer-common/constant_typers.ml index 7abc2b521..e65e02cc9 100644 --- a/src/passes/09-typing/08-typer-common/constant_typers.ml +++ b/src/passes/09-typing/08-typer-common/constant_typers.ml @@ -652,7 +652,7 @@ let rec pair_comparator : string -> typer = fun s -> typer_2 s @@ fun a b -> comparator s [a_v;b_v] None and comparator : string -> typer = fun s -> typer_2 s @@ fun a b -> - bind_or (simple_comparator s [a;b] None, pair_comparator s [a;b] None) + bind_or (pair_comparator s [a;b] None, simple_comparator s [a;b] None) let constant_typers c : (typer , typer_error) result = match c with | C_INT -> ok @@ int ; diff --git a/src/passes/09-typing/08-typer-common/errors.ml b/src/passes/09-typing/08-typer-common/errors.ml index 915b896b7..b2a6bdf13 100644 --- a/src/passes/09-typing/08-typer-common/errors.ml +++ b/src/passes/09-typing/08-typer-common/errors.ml @@ -447,10 +447,8 @@ let rec error_ppformat : display_format:string display_format -> Ast_typed.PP.type_expression t | `Typer_uncomparable_types (a,b) -> Format.fprintf f - "@[Those two types are not comparable:@ %a - %a@ %a - %a@]" - Location.pp a.location + "@[Those two types are not comparable:@ - %a@ - %a@]" Ast_typed.PP.type_expression a - Location.pp b.location Ast_typed.PP.type_expression b | `Typer_comparator_composed a -> Format.fprintf f diff --git a/src/test/contracts/negative/compare_sum_types.ligo b/src/test/contracts/negative/compare_sum_types.ligo new file mode 100644 index 000000000..0892c3991 --- /dev/null +++ b/src/test/contracts/negative/compare_sum_types.ligo @@ -0,0 +1,4 @@ +type foo is Foo | Bar + +function main (const p : foo; const s : bool) : list(operation) * bool is + ((nil : list (operation)), p = Foo) \ No newline at end of file