We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 808075d commit 0fe5b13Copy full SHA for 0fe5b13
3 files changed
lib/elixir/lib/module/types/expr.ex
@@ -768,17 +768,13 @@ defmodule Module.Types.Expr do
768
{trees, precise?, context} =
769
Pattern.of_generator(pattern, guards, type, :with, expr, meta, stack, context)
770
771
- if precise? do
772
- [pattern_type] = Pattern.of_domain(trees, stack, context)
+ [pattern_type] = Pattern.of_domain(trees, stack, context)
773
774
- {_, refined_context} =
775
- of_expr(right, pattern_type, right, %{stack | reverse_arrow: :use}, context)
+ {_, refined_context} =
+ of_expr(right, pattern_type, right, %{stack | reverse_arrow: :use}, context)
776
777
- {union(difference(type, pattern_type), else_types),
778
- reset_warnings(refined_context, context)}
779
- else
780
- {union(type, else_types), context}
781
- end
+ else_type = if precise?, do: difference(type, pattern_type), else: type
+ {union(else_type, else_types), reset_warnings(refined_context, context)}
782
end
783
784
defp with_clause(expr, stack, {else_types, context}) do
lib/elixir/lib/module/types/pattern.ex
@@ -342,7 +342,7 @@ defmodule Module.Types.Pattern do
342
of_pattern_refine(types, changed, pattern_info, tag, stack, context) do
343
{args, pattern_precise? and guard_precise?, context}
344
else
345
- {:error, context} -> {tree, false, context}
+ {:error, context} -> {args, false, context}
346
347
348
lib/elixir/test/elixir/module/types/expr_test.exs
@@ -2711,6 +2711,23 @@ defmodule Module.Types.ExprTest do
2711
) ==
2712
dynamic(union(binary(), atom([nil, :not_precise])))
2713
|> union(atom([:not_precise]))
2714
+
2715
+ assert typecheck!(
2716
+ [x],
2717
+ with :ok <- System.get_env(x) && :ok do
2718
+ {:ok, x}
2719
+ end
2720
+ ) ==
2721
+ dynamic(union(tuple([atom([:ok]), binary()]), atom([nil])))
2722
2723
2724
2725
+ with {:ok, "not precise"} <- if(y = System.get_env(x), do: {:ok, y}) do
2726
2727
2728
2729
2730
+ |> union(atom([nil]))
2731
2732
2733
test "warns on non-matching generators" do
0 commit comments