Skip to content

Commit e1936ec

Browse files
committed
Rewrite done
1 parent dddb9b6 commit e1936ec

File tree

4 files changed

+14
-35
lines changed

4 files changed

+14
-35
lines changed

lib/elixir/lib/module/types.ex

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,9 @@ defmodule Module.Types do
5252
end
5353

5454
defp warnings_from_clause(meta, args, guards, body, stack, context) do
55-
case Pattern.of_head(args, guards, meta, stack, context) do
56-
{:ok, _types, context} ->
57-
{_type, context} = Expr.of_expr(body, stack, context)
58-
context.warnings
59-
60-
{:error, context} ->
61-
context.warnings
62-
end
55+
{_types, context} = Pattern.of_head(args, guards, meta, stack, context)
56+
{_type, context} = Expr.of_expr(body, stack, context)
57+
context.warnings
6358
end
6459

6560
@doc false

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

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,8 @@ defmodule Module.Types.Expr do
358358
defp for_clause({:<-, meta, [left, expr]}, stack, context) do
359359
{pattern, guards} = extract_head([left])
360360
{_expr_type, context} = of_expr(expr, stack, context)
361-
362-
case Pattern.of_head([pattern], guards, meta, stack, context) do
363-
{:ok, _, context} -> context
364-
{:error, context} -> context
365-
end
361+
{[_type], context} = Pattern.of_head([pattern], guards, meta, stack, context)
362+
context
366363
end
367364

368365
defp for_clause({:<<>>, _, [{:<-, meta, [left, right]}]}, stack, context) do
@@ -398,14 +395,9 @@ defmodule Module.Types.Expr do
398395
defp with_clause({:<-, meta, [left, expr]}, stack, context) do
399396
{pattern, guards} = extract_head([left])
400397

401-
case Pattern.of_head([pattern], guards, meta, stack, context) do
402-
{:ok, _, context} ->
403-
{_expr_type, context} = of_expr(expr, stack, context)
404-
context
405-
406-
{:error, context} ->
407-
context
408-
end
398+
{[_type], context} = Pattern.of_head([pattern], guards, meta, stack, context)
399+
{_expr_type, context} = of_expr(expr, stack, context)
400+
context
409401
end
410402

411403
defp with_clause(expr, stack, context) do
@@ -443,14 +435,9 @@ defmodule Module.Types.Expr do
443435
Enum.reduce(clauses, context, fn {:->, meta, [head, body]}, context ->
444436
{patterns, guards} = extract_head(head)
445437

446-
case Pattern.of_head(patterns, guards, meta, stack, context) do
447-
{:ok, _, context} ->
448-
{_, context} = of_expr(body, stack, context)
449-
context
450-
451-
{:error, context} ->
452-
context
453-
end
438+
{_types, context} = Pattern.of_head(patterns, guards, meta, stack, context)
439+
{_, context} = of_expr(body, stack, context)
440+
context
454441
end)
455442
end
456443

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ defmodule Module.Types.Pattern do
3434

3535
{_trees, types, context} = of_pattern_args(patterns, expected_types, stack, context)
3636
{_, context} = Enum.map_reduce(guards, context, &of_guard(&1, @guard, &1, stack, &2))
37-
{:ok, types, context}
37+
{types, context}
3838
end
3939

4040
defp of_pattern_args([], [], _stack, context) do

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,8 @@ defmodule TypeHelper do
131131

132132
def __typecheck__(patterns, guards, body) do
133133
stack = new_stack()
134-
135-
case Pattern.of_head(patterns, guards, [], stack, new_context()) do
136-
{:ok, _types, context} -> Expr.of_expr(body, stack, context)
137-
{:error, context} -> {Module.Types.Descr.dynamic(), context}
138-
end
134+
{_types, context} = Pattern.of_head(patterns, guards, [], stack, new_context())
135+
Expr.of_expr(body, stack, context)
139136
end
140137

141138
defp expand_and_unpack(patterns, guards, body, env) do

0 commit comments

Comments
 (0)