@@ -393,6 +393,7 @@ defmodule Module.Types.Apply do
393393 case sized_order ( name , left , right , expected ) do
394394 { arg , expected , precise? , return } ->
395395 { actual , context } = of_fun . ( arg , expected , expr , stack , context )
396+ # expected is a static type, so we can use subtype? rather than compatible?
396397 result = if precise? and subtype? ( actual , expected ) , do: return , else: boolean ( )
397398 { result , context }
398399
@@ -525,9 +526,10 @@ defmodule Module.Types.Apply do
525526 { arg_type , context } = of_fun . ( arg , expected , expr , stack , context )
526527
527528 cond do
528- # Return a precise result
529- singleton? and subtype? ( arg_type , expected ) ->
530- { return ( return , [ arg_type , expected ] , stack ) , context }
529+ # expected can have dynamic terms but, since we have verified
530+ # them to be singletons, we can compute the upper bound.
531+ singleton? and subtype? ( arg_type , upper_bound ( expected ) ) ->
532+ { return , context }
531533
532534 # Singleton types with reverse polarity are negated, so we don't check for disjoint
533535 ( singleton? and not polarity ) or not is_warning ( stack ) ->
@@ -608,6 +610,8 @@ defmodule Module.Types.Apply do
608610 end
609611
610612 { actual , context } = of_fun . ( arg , expected , expr , stack , context )
613+
614+ # expected here is a static type, so subtyping relation is fine
611615 result = if precise? and subtype? ( actual , expected ) , do: return , else: boolean ( )
612616
613617 # We can skip return compare because literal is always an integer,
@@ -635,7 +639,7 @@ defmodule Module.Types.Apply do
635639 if singleton? ( type ) do
636640 expected = if polarity , do: type , else: negation ( type )
637641 { arg_type , context } = of_fun . ( arg , expected , expr , stack , context )
638- result = if subtype? ( arg_type , expected ) , do: return , else: boolean ( )
642+ result = if subtype? ( arg_type , upper_bound ( expected ) ) , do: return , else: boolean ( )
639643
640644 # Because reverse polarity means we will infer negated types
641645 # (which are naturally disjoint), we skip checks in such cases
0 commit comments