Skip to content

Commit e14608d

Browse files
committed
Avoid nested differences
1 parent a2f17be commit e14608d

5 files changed

Lines changed: 231 additions & 201 deletions

File tree

lib/elixir/lib/module/types/apply.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,9 +1486,9 @@ defmodule Module.Types.Apply do
14861486
domain(domain, clauses)
14871487
end
14881488

1489-
defp filter_domain({_type, domain, clauses}, expected, arity) do
1489+
defp filter_domain({_type, domain, clauses}, expected, _arity) do
14901490
case filter_domain(clauses, expected, [], true) do
1491-
:none -> List.duplicate(term(), arity)
1491+
:none -> domain(domain, clauses)
14921492
:all -> domain(domain, clauses)
14931493
args -> Enum.zip_with(args, fn types -> Enum.reduce(types, &union/2) end)
14941494
end

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

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -105,31 +105,62 @@ defmodule Module.Types.Of do
105105
context
106106
end
107107

108-
if gradual?(old_type) and type not in [term(), dynamic()] and not is_map_key(data, :errored) do
109-
case compatible_intersection(old_type, type) do
110-
{:error, _} when allow_empty? ->
111-
data = %{
112-
data
113-
| type: none(),
114-
off_traces: new_trace(expr, none(), stack, off_traces)
115-
}
116-
117-
{none(), %{context | vars: %{vars | version => data}}}
118-
119-
{:ok, new_type} when new_type != old_type ->
120-
data = %{
121-
data
122-
| type: new_type,
123-
off_traces: new_trace(expr, new_type, stack, off_traces)
124-
}
125-
126-
{new_type, %{context | vars: %{vars | version => data}}}
127-
128-
_ ->
129-
{old_type, context}
108+
if match?(%{pattern_info: %{allow_empty?: _}}, context) do
109+
if type not in [term(), dynamic()] and not is_map_key(data, :errored) do
110+
new_type = intersection(old_type, type)
111+
112+
case empty?(new_type) do
113+
true when allow_empty? ->
114+
data = %{
115+
data
116+
| type: none(),
117+
off_traces: new_trace(expr, none(), stack, off_traces)
118+
}
119+
120+
{none(), %{context | vars: %{vars | version => data}}}
121+
122+
false when new_type != old_type ->
123+
data = %{
124+
data
125+
| type: new_type,
126+
off_traces: new_trace(expr, new_type, stack, off_traces)
127+
}
128+
129+
{new_type, %{context | vars: %{vars | version => data}}}
130+
131+
_ ->
132+
{old_type, context}
133+
end
134+
else
135+
{old_type, context}
130136
end
131137
else
132-
{old_type, context}
138+
if gradual?(old_type) and type not in [term(), dynamic()] and not is_map_key(data, :errored) do
139+
case compatible_intersection(old_type, type) do
140+
{:error, _} when allow_empty? ->
141+
data = %{
142+
data
143+
| type: none(),
144+
off_traces: new_trace(expr, none(), stack, off_traces)
145+
}
146+
147+
{none(), %{context | vars: %{vars | version => data}}}
148+
149+
{:ok, new_type} when new_type != old_type ->
150+
data = %{
151+
data
152+
| type: new_type,
153+
off_traces: new_trace(expr, new_type, stack, off_traces)
154+
}
155+
156+
{new_type, %{context | vars: %{vars | version => data}}}
157+
158+
_ ->
159+
{old_type, context}
160+
end
161+
else
162+
{old_type, context}
163+
end
133164
end
134165
end
135166

0 commit comments

Comments
 (0)