@@ -363,14 +363,14 @@ defmodule Module.Types.Apply do
363363
364364 match? ( { false , _ } , map_fetch ( left , :__struct__ ) ) or
365365 match? ( { false , _ } , map_fetch ( right , :__struct__ ) ) ->
366- warning = { :struct_comparison , expr , context }
366+ warning = { :struct_comparison , expr , name , left , right , context }
367367 warn ( __MODULE__ , warning , elem ( expr , 1 ) , stack , context )
368368
369369 number_type? ( left ) and number_type? ( right ) ->
370370 context
371371
372372 disjoint? ( left , right ) ->
373- warning = { :mismatched_comparison , expr , context }
373+ warning = { :mismatched_comparison , expr , name , left , right , context }
374374 warn ( __MODULE__ , warning , elem ( expr , 1 ) , stack , context )
375375
376376 true ->
@@ -395,7 +395,7 @@ defmodule Module.Types.Apply do
395395 context
396396
397397 disjoint? ( left , right ) ->
398- warning = { :mismatched_comparison , expr , context }
398+ warning = { :mismatched_comparison , expr , name , left , right , context }
399399 warn ( __MODULE__ , warning , elem ( expr , 1 ) , stack , context )
400400
401401 true ->
@@ -810,7 +810,7 @@ defmodule Module.Types.Apply do
810810 }
811811 end
812812
813- def format_diagnostic ( { :mismatched_comparison , expr , context } ) do
813+ def format_diagnostic ( { :mismatched_comparison , expr , name , left , right , context } ) do
814814 traces = collect_traces ( expr , context )
815815
816816 % {
@@ -821,6 +821,10 @@ defmodule Module.Types.Apply do
821821 comparison between distinct types found:
822822
823823 #{ expr_to_string ( expr ) |> indent ( 4 ) }
824+
825+ given types:
826+
827+ #{ type_comparison_to_string ( name , left , right ) |> indent ( 4 ) }
824828 """ ,
825829 format_traces ( traces ) ,
826830 """
@@ -833,7 +837,7 @@ defmodule Module.Types.Apply do
833837 }
834838 end
835839
836- def format_diagnostic ( { :struct_comparison , expr , context } ) do
840+ def format_diagnostic ( { :struct_comparison , expr , name , left , right , context } ) do
837841 traces = collect_traces ( expr , context )
838842
839843 % {
@@ -844,6 +848,10 @@ defmodule Module.Types.Apply do
844848 comparison with structs found:
845849
846850 #{ expr_to_string ( expr ) |> indent ( 4 ) }
851+
852+ given types:
853+
854+ #{ type_comparison_to_string ( name , left , right ) |> indent ( 4 ) }
847855 """ ,
848856 format_traces ( traces ) ,
849857 """
@@ -933,6 +941,15 @@ defmodule Module.Types.Apply do
933941
934942 alias Inspect.Algebra , as: IA
935943
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+
936953 defp clauses_args_to_quoted_string ( [ { args , _return } ] , converter ) do
937954 "\n " <> ( clause_args_to_quoted_string ( args , converter ) |> indent ( 4 ) )
938955 end
0 commit comments