Skip to content

Commit 72f2646

Browse files
committed
More progress
1 parent 5994bfc commit 72f2646

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,20 @@ defmodule Module.Types.Pattern do
437437
end
438438
end)
439439

440-
intersection =
441-
cond do
442-
static == [] -> {:intersection, dynamic}
443-
dynamic == [] -> Enum.reduce(static, &intersection/2)
444-
true -> {:intersection, [Enum.reduce(static, &intersection/2) | dynamic]}
445-
end
440+
if dynamic == [] do
441+
{Enum.reduce(static, &intersection/2), context}
442+
else
443+
# The dynamic parts have to be recomputed whenever they change
444+
{var, context} =
445+
of_pattern(var, [%{root: {:intersection, dynamic}, expr: expr}], stack, context)
446446

447-
# But also build the new path with the intersection
448-
of_pattern(var, [%{root: intersection, expr: expr}], stack, context)
447+
# But the static parts we push down as part of the argument intersection
448+
if static == [] do
449+
{var, context}
450+
else
451+
{{:intersection, [var, Enum.reduce(static, &intersection/2)]}, context}
452+
end
453+
end
449454
end
450455

451456
# %Struct{...}

0 commit comments

Comments
 (0)