Skip to content

Commit 89849ac

Browse files
committed
Fewer ok
1 parent 6ff6b44 commit 89849ac

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ defmodule Module.Types.Expr do
308308
Of.map_fetch(expr, type, key_or_fun, stack, context)
309309
else
310310
{mods, context} = Of.remote(type, key_or_fun, 0, [:dot], expr, meta, stack, context)
311-
apply_many(mods, key_or_fun, [], expr, stack, context)
311+
{type, context} = apply_many(mods, key_or_fun, [], expr, stack, context)
312+
{:ok, type, context}
312313
end
313314
end
314315
end
@@ -318,7 +319,8 @@ defmodule Module.Types.Expr do
318319
with {:ok, remote_type, context} <- of_expr(remote, stack, context),
319320
{:ok, args_types, context} <- map_reduce_ok(args, context, &of_expr(&1, stack, &2)) do
320321
{mods, context} = Of.remote(remote_type, name, length(args), expr, meta, stack, context)
321-
apply_many(mods, name, args_types, expr, stack, context)
322+
{type, context} = apply_many(mods, name, args_types, expr, stack, context)
323+
{:ok, type, context}
322324
end
323325
end
324326

@@ -464,20 +466,20 @@ defmodule Module.Types.Expr do
464466
defp error_type(), do: dynamic()
465467

466468
defp apply_many([], _function, _args_types, _expr, _stack, context) do
467-
{:ok, dynamic(), context}
469+
{dynamic(), context}
468470
end
469471

470472
defp apply_many([mod], function, args_types, expr, stack, context) do
471473
Of.apply(mod, function, args_types, expr, stack, context)
472474
end
473475

474476
defp apply_many(mods, function, args_types, expr, stack, context) do
475-
with {:ok, returns, context} <-
476-
map_reduce_ok(mods, context, fn mod, context ->
477-
Of.apply(mod, function, args_types, expr, stack, context)
478-
end) do
479-
{:ok, Enum.reduce(returns, &union/2), context}
480-
end
477+
{returns, context} =
478+
Enum.map_reduce(mods, context, fn mod, context ->
479+
Of.apply(mod, function, args_types, expr, stack, context)
480+
end)
481+
482+
{Enum.reduce(returns, &union/2), context}
481483
end
482484

483485
defp of_clauses(clauses, stack, context) do

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,10 @@ defmodule Module.Types.Of do
336336
when is_integer(index) do
337337
case tuple_fetch(type, index - 1) do
338338
{_optional?, value_type} ->
339-
{:ok, value_type, context}
339+
{value_type, context}
340340

341341
reason ->
342-
{:ok, dynamic(), error({reason, expr, type, index - 1, context}, meta, stack, context)}
342+
{dynamic(), error({reason, expr, type, index - 1, context}, meta, stack, context)}
343343
end
344344
end
345345

@@ -351,24 +351,24 @@ defmodule Module.Types.Of do
351351
match?({false, _}, map_fetch(left, :__struct__)) or
352352
match?({false, _}, map_fetch(right, :__struct__)) ->
353353
warning = {:struct_comparison, expr, context}
354-
{:ok, result, error(warning, elem(expr, 1), stack, context)}
354+
{result, error(warning, elem(expr, 1), stack, context)}
355355

356356
number_type?(left) and number_type?(right) ->
357-
{:ok, result, context}
357+
{result, context}
358358

359359
disjoint?(left, right) ->
360360
warning = {:mismatched_comparison, expr, context}
361-
{:ok, result, error(warning, elem(expr, 1), stack, context)}
361+
{result, error(warning, elem(expr, 1), stack, context)}
362362

363363
true ->
364-
{:ok, result, context}
364+
{result, context}
365365
end
366366
end
367367

368368
def apply(mod, name, args, expr, stack, context) do
369369
case :elixir_rewrite.inline(mod, name, length(args)) do
370370
{mod, name} -> apply(mod, name, args, expr, stack, context)
371-
false -> {:ok, dynamic(), context}
371+
false -> {dynamic(), context}
372372
end
373373
end
374374

lib/elixir/lib/module/types/pattern.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,8 @@ defmodule Module.Types.Pattern do
672672
when is_atom(function) do
673673
with {:ok, args_type, context} <-
674674
map_reduce_ok(args, context, &of_guard(&1, dynamic(), expr, stack, &2)) do
675-
Of.apply(:erlang, function, args_type, expr, stack, context)
675+
{type, context} = Of.apply(:erlang, function, args_type, expr, stack, context)
676+
{:ok, type, context}
676677
end
677678
end
678679

0 commit comments

Comments
 (0)