@@ -403,10 +403,8 @@ defmodule Module.Types.Pattern do
403
403
# bar, {:ok, baz}
404
404
# bar, {:ok, bat}
405
405
406
- expanded_args =
407
- args
408
- |> Enum . map ( & flatten_union ( & 1 , context ) )
409
- |> cartesian_product ( )
406
+ flatten_args = Enum . map ( args , & flatten_union ( & 1 , context ) )
407
+ cartesian_args = cartesian_product ( flatten_args )
410
408
411
409
# Remove clauses that do not match the expected type
412
410
# Ignore type variables in parameters by changing them to dynamic
@@ -425,11 +423,11 @@ defmodule Module.Types.Pattern do
425
423
# the type contexts from unifying argument and parameter to
426
424
# infer type variables in arguments
427
425
result =
428
- flat_map_ok ( expanded_args , fn expanded_args ->
426
+ flat_map_ok ( cartesian_args , fn cartesian_args ->
429
427
result =
430
428
Enum . flat_map ( clauses , fn { params , return } ->
431
429
result =
432
- map_ok ( Enum . zip ( expanded_args , params ) , fn { arg , param } ->
430
+ map_ok ( Enum . zip ( cartesian_args , params ) , fn { arg , param } ->
433
431
case unify ( arg , param , stack , context ) do
434
432
{ :ok , _type , context } -> { :ok , context }
435
433
{ :error , reason } -> { :error , reason }
@@ -453,7 +451,13 @@ defmodule Module.Types.Pattern do
453
451
{ :ok , returns_contexts } ->
454
452
{ success_returns , contexts } = Enum . unzip ( returns_contexts )
455
453
contexts = Enum . concat ( contexts )
456
- indexes = Enum . uniq ( Enum . flat_map ( args , & collect_var_indexes_from_type / 1 ) )
454
+
455
+ indexes =
456
+ for types <- flatten_args ,
457
+ type <- types ,
458
+ index <- collect_var_indexes_from_type ( type ) ,
459
+ do: index ,
460
+ uniq: true
457
461
458
462
# Build unions from collected type contexts to unify with
459
463
# type variables from arguments
0 commit comments