Skip to content

Commit 47b712e

Browse files
committed
Unify apply and remote handling
1 parent 04741c8 commit 47b712e

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

lib/elixir/lib/module/types/expr.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ defmodule Module.Types.Expr do
274274
if Keyword.get(meta, :no_parens, false) do
275275
Of.map_fetch(expr, type, key_or_fun, stack, context)
276276
else
277-
{mods, context} = Of.remote(type, key_or_fun, 0, [:dot], expr, meta, stack, context)
277+
{mods, context} = Of.modules(type, key_or_fun, 0, [:dot], expr, meta, stack, context)
278278
apply_many(mods, key_or_fun, [], expr, stack, context)
279279
end
280280
end
@@ -283,7 +283,7 @@ defmodule Module.Types.Expr do
283283
def of_expr({{:., _, [remote, name]}, meta, args} = expr, stack, context) do
284284
{remote_type, context} = of_expr(remote, stack, context)
285285
{args_types, context} = Enum.map_reduce(args, context, &of_expr(&1, stack, &2))
286-
{mods, context} = Of.remote(remote_type, name, length(args), expr, meta, stack, context)
286+
{mods, context} = Of.modules(remote_type, name, length(args), expr, meta, stack, context)
287287
apply_many(mods, name, args_types, expr, stack, context)
288288
end
289289

@@ -297,7 +297,8 @@ defmodule Module.Types.Expr do
297297
{remote_type, context} = of_expr(remote, stack, context)
298298
# TODO: We cannot return the unions of functions. Do we forbid this?
299299
# Do we check it is always the same return type? Do we simply say it is a function?
300-
{_mods, context} = Of.remote(remote_type, name, arity, expr, meta, stack, context)
300+
{mods, context} = Of.modules(remote_type, name, arity, expr, meta, stack, context)
301+
context = Enum.reduce(mods, context, &Of.remote(&1, name, arity, meta, stack, &2))
301302
{fun(), context}
302303
end
303304

lib/elixir/lib/module/types/of.ex

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ defmodule Module.Types.Of do
293293
context
294294
end
295295

296-
## Apply
296+
## Remotes
297297

298298
# TODO: Implement element without a literal index
299299

@@ -399,23 +399,25 @@ defmodule Module.Types.Of do
399399
end
400400
end
401401

402-
def apply(mod, name, args, expr, stack, context) do
403-
case :elixir_rewrite.inline(mod, name, length(args)) do
404-
{mod, name} -> apply(mod, name, args, expr, stack, context)
405-
false -> {dynamic(), context}
402+
def apply(mod, name, args_types, expr, stack, context) do
403+
arity = length(args_types)
404+
405+
case :elixir_rewrite.inline(mod, name, arity) do
406+
{mod, name} ->
407+
apply(mod, name, args_types, expr, stack, context)
408+
409+
false ->
410+
context = remote(mod, name, arity, elem(expr, 1), stack, context)
411+
{dynamic(), context}
406412
end
407413
end
408414

409-
## Remote
410-
411-
def remote(type, fun, arity, hints \\ [], expr, meta, stack, context) do
415+
@doc """
416+
Returns the modules for a given call.
417+
"""
418+
def modules(type, fun, arity, hints \\ [], expr, meta, stack, context) do
412419
case atom_fetch(type) do
413420
{_, mods} ->
414-
context =
415-
Enum.reduce(mods, context, fn mod, context ->
416-
remote(mod, fun, arity, meta, stack, context)
417-
end)
418-
419421
{mods, context}
420422

421423
:error ->

0 commit comments

Comments
 (0)