@@ -21,21 +21,17 @@ defmodule Module.Types.Pattern do
2121 defp previous_subtype? ( _ , [ ] ) , do: false
2222 defp previous_subtype? ( [ ] , _ ) , do: true
2323
24- defp previous_subtype? ( [ type ] , previous ) ,
25- do: subtype? ( type , Enum . reduce ( previous , none ( ) , & union ( & 2 , hd ( & 1 ) ) ) )
26-
27- defp previous_subtype? ( args , previous ) do
28- subtype? (
29- args_to_domain ( args ) ,
30- Enum . reduce ( previous , none ( ) , & union ( & 2 , args_to_domain ( & 1 ) ) )
31- )
32- end
24+ defp previous_subtype? ( args , previous ) ,
25+ do: subtype? ( args_to_previous ( args ) , Enum . reduce ( previous , none ( ) , & union ( & 2 , elem ( & 1 , 1 ) ) ) )
3326
3427 defp concat_previous ( [ ] , previous ) ,
3528 do: previous
3629
3730 defp concat_previous ( types , previous ) ,
38- do: [ types | previous ]
31+ do: [ { types , args_to_previous ( types ) } | previous ]
32+
33+ defp args_to_previous ( [ type ] ) , do: upper_bound ( type )
34+ defp args_to_previous ( types ) , do: args_to_static_domain ( types )
3935
4036 defp of_pattern_previous ( types , [ ] , _trees , _pattern_info , _tag , _stack , _context ) do
4137 { :ok , types }
@@ -45,11 +41,11 @@ defmodule Module.Types.Pattern do
4541 types =
4642 case types do
4743 [ type ] ->
48- [ Enum . reduce ( previous , type , & difference ( & 2 , hd ( & 1 ) ) ) ]
44+ [ Enum . reduce ( previous , type , & difference ( & 2 , elem ( & 1 , 1 ) ) ) ]
4945
5046 [ _ | _ ] ->
5147 previous
52- |> Enum . reduce ( args_to_domain ( types ) , & difference ( & 2 , args_to_domain ( & 1 ) ) )
48+ |> Enum . reduce ( args_to_domain ( types ) , & difference ( & 2 , elem ( & 1 , 1 ) ) )
5349 |> domain_to_flat_args ( types )
5450 end
5551
@@ -63,9 +59,9 @@ defmodule Module.Types.Pattern do
6359 end
6460
6561 defp previous_to_string ( previous ) do
66- Enum . map_join ( previous , "\n " , fn types ->
62+ Enum . map_join ( previous , "\n " , fn { types , _ } ->
6763 types
68- |> Enum . map_join ( ", " , & to_quoted_string / 1 )
64+ |> Enum . map_join ( ", " , & ( & 1 |> upper_bound ( ) |> to_quoted_string ( ) ) )
6965 |> indent ( 4 )
7066 end )
7167 end
@@ -269,9 +265,7 @@ defmodule Module.Types.Pattern do
269265
270266 defp trees_to_args_types ( trees , stack , context ) do
271267 Enum . map ( trees , fn { tree , _ , _ } ->
272- tree
273- |> of_pattern_tree ( stack , context )
274- |> upper_bound ( )
268+ of_pattern_tree ( tree , stack , context )
275269 end )
276270 end
277271
0 commit comments