Skip to content

Commit 7819a73

Browse files
committed
Simplify compatibility check
1 parent f659598 commit 7819a73

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/elixir/lib/module/types/descr.ex

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ defmodule Module.Types.Descr do
10861086
case :maps.take(:dynamic, fun) do
10871087
:error ->
10881088
if fun_only?(fun) do
1089-
fun_apply_with_strategy(fun, fun, nil, arguments)
1089+
fun_apply_with_strategy(fun, nil, arguments)
10901090
else
10911091
:badfun
10921092
end
@@ -1100,7 +1100,7 @@ defmodule Module.Types.Descr do
11001100

11011101
{fun_dynamic, fun_static} ->
11021102
if fun_only?(fun_static) do
1103-
fun_apply_with_strategy(fun, fun_static, fun_dynamic, arguments)
1103+
fun_apply_with_strategy(fun_static, fun_dynamic, arguments)
11041104
else
11051105
:badfun
11061106
end
@@ -1109,7 +1109,7 @@ defmodule Module.Types.Descr do
11091109

11101110
defp fun_only?(descr), do: empty?(Map.delete(descr, :fun))
11111111

1112-
defp fun_apply_with_strategy(fun, fun_static, fun_dynamic, arguments) do
1112+
defp fun_apply_with_strategy(fun_static, fun_dynamic, arguments) do
11131113
args_dynamic? = any_dynamic?(arguments)
11141114
args_domain = args_to_domain(arguments)
11151115
static? = fun_dynamic == nil and not args_dynamic?
@@ -1122,8 +1122,7 @@ defmodule Module.Types.Descr do
11221122
{:badarg, domain_to_flat_args(domain, arity)}
11231123

11241124
not subtype?(args_domain, domain) ->
1125-
# TODO: This compatibility check is not enough
1126-
if static? or not compatible?(fun, fun(arguments, term())) do
1125+
if static? or not compatible?(args_domain, domain) do
11271126
{:badarg, domain_to_flat_args(domain, arity)}
11281127
else
11291128
{:ok, dynamic()}
@@ -1174,7 +1173,7 @@ defmodule Module.Types.Descr do
11741173
:badfun ->
11751174
case fun_normalize(fun_dynamic, arity, :dynamic) do
11761175
{:ok, dynamic_domain, dynamic_arrows} ->
1177-
{:ok, dynamic_domain, [], dynamic_arrows}
1176+
{:ok, union(dynamic_domain, dynamic()), [], dynamic_arrows}
11781177

11791178
error ->
11801179
error

lib/elixir/test/elixir/module/types/descr_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,8 @@ defmodule Module.Types.DescrTest do
826826
assert fun_apply(fun([integer()], atom()), [integer()]) == {:ok, atom()}
827827
assert fun_apply(fun([integer()], atom()), [float()]) == {:badarg, [integer()]}
828828
assert fun_apply(fun([integer()], atom()), [term()]) == {:badarg, [integer()]}
829+
assert fun_apply(fun([integer()], atom()), [dynamic()]) == {:ok, dynamic()}
830+
829831
assert fun_apply(fun([integer()], none()), [integer()]) == {:ok, none()}
830832
assert fun_apply(fun([integer()], term()), [integer()]) == {:ok, term()}
831833

0 commit comments

Comments
 (0)