@@ -363,14 +363,14 @@ defmodule Module.Types.Apply do
363
363
364
364
match? ( { false , _ } , map_fetch ( left , :__struct__ ) ) or
365
365
match? ( { false , _ } , map_fetch ( right , :__struct__ ) ) ->
366
- warning = { :struct_comparison , expr , context }
366
+ warning = { :struct_comparison , expr , name , left , right , context }
367
367
warn ( __MODULE__ , warning , elem ( expr , 1 ) , stack , context )
368
368
369
369
number_type? ( left ) and number_type? ( right ) ->
370
370
context
371
371
372
372
disjoint? ( left , right ) ->
373
- warning = { :mismatched_comparison , expr , context }
373
+ warning = { :mismatched_comparison , expr , name , left , right , context }
374
374
warn ( __MODULE__ , warning , elem ( expr , 1 ) , stack , context )
375
375
376
376
true ->
@@ -395,7 +395,7 @@ defmodule Module.Types.Apply do
395
395
context
396
396
397
397
disjoint? ( left , right ) ->
398
- warning = { :mismatched_comparison , expr , context }
398
+ warning = { :mismatched_comparison , expr , name , left , right , context }
399
399
warn ( __MODULE__ , warning , elem ( expr , 1 ) , stack , context )
400
400
401
401
true ->
@@ -810,7 +810,7 @@ defmodule Module.Types.Apply do
810
810
}
811
811
end
812
812
813
- def format_diagnostic ( { :mismatched_comparison , expr , context } ) do
813
+ def format_diagnostic ( { :mismatched_comparison , expr , name , left , right , context } ) do
814
814
traces = collect_traces ( expr , context )
815
815
816
816
% {
@@ -821,6 +821,10 @@ defmodule Module.Types.Apply do
821
821
comparison between distinct types found:
822
822
823
823
#{ expr_to_string ( expr ) |> indent ( 4 ) }
824
+
825
+ given types:
826
+
827
+ #{ type_comparison_to_string ( name , left , right ) |> indent ( 4 ) }
824
828
""" ,
825
829
format_traces ( traces ) ,
826
830
"""
@@ -833,7 +837,7 @@ defmodule Module.Types.Apply do
833
837
}
834
838
end
835
839
836
- def format_diagnostic ( { :struct_comparison , expr , context } ) do
840
+ def format_diagnostic ( { :struct_comparison , expr , name , left , right , context } ) do
837
841
traces = collect_traces ( expr , context )
838
842
839
843
% {
@@ -844,6 +848,10 @@ defmodule Module.Types.Apply do
844
848
comparison with structs found:
845
849
846
850
#{ expr_to_string ( expr ) |> indent ( 4 ) }
851
+
852
+ given types:
853
+
854
+ #{ type_comparison_to_string ( name , left , right ) |> indent ( 4 ) }
847
855
""" ,
848
856
format_traces ( traces ) ,
849
857
"""
@@ -933,6 +941,15 @@ defmodule Module.Types.Apply do
933
941
934
942
alias Inspect.Algebra , as: IA
935
943
944
+ defp type_comparison_to_string ( fun , left , right ) do
945
+ { Kernel , fun , [ left , right ] , _ } = :elixir_rewrite . erl_to_ex ( :erlang , fun , [ left , right ] )
946
+
947
+ { fun , [ ] , [ to_quoted ( left ) , to_quoted ( right ) ] }
948
+ |> Code.Formatter . to_algebra ( )
949
+ |> Inspect.Algebra . format ( 98 )
950
+ |> IO . iodata_to_binary ( )
951
+ end
952
+
936
953
defp clauses_args_to_quoted_string ( [ { args , _return } ] , converter ) do
937
954
"\n " <> ( clause_args_to_quoted_string ( args , converter ) |> indent ( 4 ) )
938
955
end
0 commit comments