Skip to content

Commit 6cb9140

Browse files
committed
Remove unnecessary empty checks when computing previous types
1 parent bffb696 commit 6cb9140

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,21 @@ defmodule Module.Types.Pattern do
3131
defp args_to_previous([type]), do: upper_bound(type)
3232
defp args_to_previous(types), do: args_to_static_domain(types)
3333

34-
defp of_pattern_previous(types, {[], _}, _trees, _pattern_info, _tag, _stack, _context) do
35-
{:ok, types, false}
34+
defp of_pattern_previous(types, {[], _}, _stack) do
35+
{types, false}
3636
end
3737

38-
defp of_pattern_previous(types, {_, descr}, trees, pattern_info, tag, stack, context) do
38+
defp of_pattern_previous(types, {_, descr}, stack) do
3939
refined_types =
4040
case types do
4141
[type] -> [difference(type, descr)]
4242
[_ | _] -> args_to_domain(types) |> difference(descr) |> domain_to_flat_args(types)
4343
end
4444

45-
if index = Enum.find_index(types, &empty?/1) do
46-
{_, _, pattern} = Enum.fetch!(trees, index)
47-
context = badpattern_error(pattern, index, tag, stack, context)
48-
{:error, error_vars(pattern_info, context)}
49-
else
50-
# check_previous? is an optimization. If types have not changed,
51-
# it means args_types and previous are disjoint, and any further
52-
# refinement will keep them disjoint, so no need to check for previous.
53-
{:ok, refined_types, stack.mode != :infer and types != refined_types}
54-
end
45+
# check_previous? is an optimization. If types have not changed,
46+
# it means args_types and previous are disjoint, and any further
47+
# refinement will keep them disjoint, so no need to check for previous.
48+
{refined_types, stack.mode != :infer and types != refined_types}
5549
end
5650

5751
defp previous_to_string({list, _}) do
@@ -247,8 +241,7 @@ defmodule Module.Types.Pattern do
247241
else
248242
_ -> nil
249243
end),
250-
{:ok, types, check_previous?} <-
251-
of_pattern_previous(types, previous, trees, pattern_info, tag, stack, context),
244+
{types, check_previous?} = of_pattern_previous(types, previous, stack),
252245
{:ok, _types, context} <-
253246
of_pattern_refine(types, changed, pattern_info, tag, stack, context) do
254247
{trees, pattern_precise? and guard_precise?, check_previous?,

0 commit comments

Comments
 (0)