Skip to content

Commit c4275e3

Browse files
authored
Reject empty args in dynamic fun_apply (#15254)
1 parent 1bf7bb0 commit c4275e3

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,12 +1442,10 @@ defmodule Module.Types.Descr do
14421442
static? = fun_dynamic == nil and Enum.all?(arguments, fn arg -> not gradual?(arg) end)
14431443
arity = length(arguments)
14441444

1445-
with {:ok, domain, static_arrows, dynamic_arrows} <-
1445+
with false <- Enum.any?(arguments, &empty?/1),
1446+
{:ok, domain, static_arrows, dynamic_arrows} <-
14461447
fun_normalize_both(fun_static, fun_dynamic, arity) do
14471448
cond do
1448-
Enum.any?(arguments, &empty?/1) ->
1449-
{:badarg, domain_to_flat_args(domain, arity)}
1450-
14511449
# The domain here is the extended gradual domain computed by
14521450
# fun_normalize_both/3. If the argument does not satisfy it, we
14531451
# check compatibility before rejecting.
@@ -1498,6 +1496,9 @@ defmodule Module.Types.Descr do
14981496
dynamic(fun_apply_static(arguments, dynamic_arrows))
14991497
)}
15001498
end
1499+
else
1500+
true -> {:badarg, arguments}
1501+
error -> error
15011502
end
15021503
end
15031504

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,7 @@ defmodule Module.Types.DescrTest do
12141214
assert fun_apply(dynamic_fun([integer()], atom()), [float()]) == {:ok, dynamic()}
12151215
assert fun_apply(dynamic_fun([integer()], atom()), [term()]) == {:ok, dynamic()}
12161216
assert fun_apply(dynamic_fun([integer()], none()), [integer()]) == {:ok, dynamic(none())}
1217+
assert fun_apply(dynamic(fun([integer()], integer())), [none()]) == {:badarg, [none()]}
12171218
assert fun_apply(dynamic_fun([integer()], term()), [integer()]) == {:ok, dynamic()}
12181219

12191220
# Dynamic return and dynamic args

0 commit comments

Comments
 (0)