rework error when comparing two sum types

This commit is contained in:
Lesenechal Remi 2020-06-17 18:40:32 +02:00 committed by Suzanne Dupéron
parent ae4a13b63f
commit 0cf9dc576e
4 changed files with 24 additions and 4 deletions

View File

@ -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' |}]

View File

@ -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 ;

View File

@ -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
"@[<hv>Those two types are not comparable:@ %a - %a@ %a - %a@]"
Location.pp a.location
"@[<hv>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

View File

@ -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)