Skip to content

Commit 5efcb4d

Browse files
committed
Rename non_empty_list/2 -> non_empty_maybe_improper_list/2
1 parent 73e5fd2 commit 5efcb4d

File tree

9 files changed

+65
-41
lines changed

9 files changed

+65
-41
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,13 @@ defmodule Module.Types.Apply do
224224
{:erlang, :++,
225225
[
226226
{[empty_list(), term()], dynamic(term())},
227-
{[non_empty_list(term()), term()], dynamic(non_empty_list(term(), term()))}
227+
{[non_empty_list(term()), term()],
228+
dynamic(non_empty_maybe_improper_list(term(), term()))}
228229
]},
229230
{:erlang, :--, [{[list(term()), list(term())], dynamic(list(term()))}]},
230231
{:erlang, :andalso, [{[boolean(), term()], dynamic()}]},
231232
{:erlang, :delete_element, [{[integer(), open_tuple([])], dynamic(open_tuple([]))}]},
232-
{:erlang, :hd, [{[non_empty_list(term(), term())], dynamic()}]},
233+
{:erlang, :hd, [{[non_empty_maybe_improper_list(term(), term())], dynamic()}]},
233234
{:erlang, :element, [{[integer(), open_tuple([])], dynamic()}]},
234235
{:erlang, :insert_element,
235236
[{[integer(), open_tuple([]), term()], dynamic(open_tuple([]))}]},
@@ -239,7 +240,7 @@ defmodule Module.Types.Apply do
239240
{:erlang, :orelse, [{[boolean(), term()], dynamic()}]},
240241
{:erlang, :send, [{[send_destination, term()], dynamic()}]},
241242
{:erlang, :setelement, [{[integer(), open_tuple([]), term()], dynamic(open_tuple([]))}]},
242-
{:erlang, :tl, [{[non_empty_list(term(), term())], dynamic()}]},
243+
{:erlang, :tl, [{[non_empty_maybe_improper_list(term(), term())], dynamic()}]},
243244
{:erlang, :tuple_to_list, [{[open_tuple([])], dynamic(list(term()))}]}
244245
] do
245246
[arity] = Enum.map(clauses, fn {args, _return} -> length(args) end) |> Enum.uniq()
@@ -314,11 +315,11 @@ defmodule Module.Types.Apply do
314315
end
315316

316317
def remote_domain(:erlang, :hd, [_list], expected, _meta, _stack, context) do
317-
{:hd, [non_empty_list(expected, term())], context}
318+
{:hd, [non_empty_maybe_improper_list(expected, term())], context}
318319
end
319320

320321
def remote_domain(:erlang, :tl, [_list], _expected, _meta, _stack, context) do
321-
{:tl, [non_empty_list(term(), term())], context}
322+
{:tl, [non_empty_maybe_improper_list(term(), term())], context}
322323
end
323324

324325
def remote_domain(:erlang, name, [_left, _right], _expected, _meta, stack, context)
@@ -1151,7 +1152,7 @@ defmodule Module.Types.Apply do
11511152
args_docs_to_quoted_string(converter.(docs))
11521153
end
11531154

1154-
@composite_types non_empty_list(term(), term())
1155+
@composite_types non_empty_maybe_improper_list(term(), term())
11551156
|> union(tuple())
11561157
|> union(open_map())
11571158
|> union(fun())

lib/elixir/lib/module/types/descr.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ defmodule Module.Types.Descr do
7474
def float(), do: %{bitmap: @bit_float}
7575
def fun(), do: %{bitmap: @bit_fun}
7676
def list(type), do: list_descr(type, @empty_list, true)
77-
def non_empty_list(type, tail \\ @empty_list), do: list_descr(type, tail, false)
77+
def non_empty_list(type), do: list_descr(type, @empty_list, false)
78+
def non_empty_maybe_improper_list(type, tail), do: list_descr(type, tail, false)
7879
def improper_list(), do: improper_list(term(), term())
7980
def improper_list(type, :term), do: list_descr(type, @not_list, false)
8081
def improper_list(type, tail), do: list_descr(type, difference(tail, list(term())), false)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ defmodule Module.Types.Expr do
109109
of_expr(suffix, tl_type, expr, stack, context)
110110
end
111111

112-
{non_empty_list(Enum.reduce(prefix, &union/2), suffix), context}
112+
{non_empty_maybe_improper_list(Enum.reduce(prefix, &union/2), suffix), context}
113113
end
114114
end
115115

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ defmodule Module.Types.Of do
132132
{Float, float()},
133133
{Function, fun()},
134134
{Integer, integer()},
135-
{List, union(empty_list(), non_empty_list(term(), term()))},
135+
{List, union(empty_list(), non_empty_maybe_improper_list(term(), term()))},
136136
{Map, open_map(__struct__: if_set(negation(atom())))},
137137
{Port, port()},
138138
{PID, pid()},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ defmodule Module.Types.Pattern do
345345
def of_pattern_tree({:non_empty_list, [head | tail], suffix}, context) do
346346
tail
347347
|> Enum.reduce(of_pattern_tree(head, context), &union(of_pattern_tree(&1, context), &2))
348-
|> non_empty_list(of_pattern_tree(suffix, context))
348+
|> non_empty_maybe_improper_list(of_pattern_tree(suffix, context))
349349
end
350350

351351
def of_pattern_tree({:intersection, entries}, context) do
@@ -639,7 +639,7 @@ defmodule Module.Types.Pattern do
639639

640640
case {static, dynamic} do
641641
{static, []} when is_descr(suffix) ->
642-
{non_empty_list(Enum.reduce(static, &union/2), suffix), context}
642+
{non_empty_maybe_improper_list(Enum.reduce(static, &union/2), suffix), context}
643643

644644
{[], dynamic} ->
645645
{{:non_empty_list, dynamic, suffix}, context}
@@ -685,7 +685,7 @@ defmodule Module.Types.Pattern do
685685
Enum.map_reduce(prefix, context, &of_guard(&1, term(), expr, stack, &2))
686686

687687
{suffix, context} = of_guard(suffix, term(), expr, stack, context)
688-
{non_empty_list(Enum.reduce(prefix, &union/2), suffix), context}
688+
{non_empty_maybe_improper_list(Enum.reduce(prefix, &union/2), suffix), context}
689689
end
690690

691691
# {left, right}

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

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ defmodule Module.Types.DescrTest do
4444
float(),
4545
binary(),
4646
open_map(),
47-
non_empty_list(term(), term()),
47+
non_empty_maybe_improper_list(term(), term()),
4848
empty_list(),
4949
tuple(),
5050
fun(),
@@ -435,7 +435,8 @@ defmodule Module.Types.DescrTest do
435435
refute empty?(difference(open_map(), empty_map()))
436436
end
437437

438-
defp list(elem_type, tail_type), do: union(empty_list(), non_empty_list(elem_type, tail_type))
438+
defp list(elem_type, tail_type),
439+
do: union(empty_list(), non_empty_maybe_improper_list(elem_type, tail_type))
439440

440441
test "list" do
441442
# Basic list type differences
@@ -471,35 +472,44 @@ defmodule Module.Types.DescrTest do
471472
|> equal?(list(atom()))
472473

473474
assert difference(list(integer(), float()), list(number(), integer()))
474-
|> equal?(non_empty_list(integer(), difference(float(), integer())))
475+
|> equal?(non_empty_maybe_improper_list(integer(), difference(float(), integer())))
475476

476477
# Empty list with last element
477478
assert difference(empty_list(), list(integer(), atom())) == none()
478479

479480
assert difference(list(integer(), atom()), empty_list()) ==
480-
non_empty_list(integer(), atom())
481+
non_empty_maybe_improper_list(integer(), atom())
481482

482483
# List with any type and specific last element
483484
assert difference(list(term(), term()), list(term(), integer()))
484485
|> equal?(
485-
non_empty_list(term(), negation(union(integer(), non_empty_list(term(), term()))))
486+
non_empty_maybe_improper_list(
487+
term(),
488+
negation(union(integer(), non_empty_maybe_improper_list(term(), term())))
489+
)
486490
)
487491

488492
# Nested lists with last element
489493
assert difference(list(list(integer()), atom()), list(list(number()), boolean()))
490494
|> equal?(
491495
union(
492-
non_empty_list(list(integer()), difference(atom(), boolean())),
493-
non_empty_list(difference(list(integer()), list(number())), atom())
496+
non_empty_maybe_improper_list(list(integer()), difference(atom(), boolean())),
497+
non_empty_maybe_improper_list(
498+
difference(list(integer()), list(number())),
499+
atom()
500+
)
494501
)
495502
)
496503

497504
# Union types in last element
498505
assert difference(list(integer(), union(atom(), binary())), list(number(), atom()))
499506
|> equal?(
500507
union(
501-
non_empty_list(integer(), binary()),
502-
non_empty_list(difference(integer(), number()), union(atom(), binary()))
508+
non_empty_maybe_improper_list(integer(), binary()),
509+
non_empty_maybe_improper_list(
510+
difference(integer(), number()),
511+
union(atom(), binary())
512+
)
503513
)
504514
)
505515

@@ -511,7 +521,7 @@ defmodule Module.Types.DescrTest do
511521

512522
# Difference with proper list
513523
assert difference(list(integer(), atom()), list(integer())) ==
514-
non_empty_list(integer(), atom())
524+
non_empty_maybe_improper_list(integer(), atom())
515525
end
516526
end
517527

@@ -719,8 +729,10 @@ defmodule Module.Types.DescrTest do
719729

720730
# If term() is in the tail, it means list(term()) is in the tail
721731
# and therefore any term can be returned from hd.
722-
assert list_hd(non_empty_list(atom(), term())) == {false, term()}
723-
assert list_hd(non_empty_list(atom(), negation(list(term(), term())))) == {false, atom()}
732+
assert list_hd(non_empty_maybe_improper_list(atom(), term())) == {false, term()}
733+
734+
assert list_hd(non_empty_maybe_improper_list(atom(), negation(list(term(), term())))) ==
735+
{false, atom()}
724736
end
725737

726738
test "list_tl" do
@@ -732,18 +744,26 @@ defmodule Module.Types.DescrTest do
732744

733745
assert list_tl(non_empty_list(integer())) == {false, list(integer())}
734746

735-
assert list_tl(non_empty_list(integer(), atom())) ==
736-
{false, union(atom(), non_empty_list(integer(), atom()))}
747+
assert list_tl(non_empty_maybe_improper_list(integer(), atom())) ==
748+
{false, union(atom(), non_empty_maybe_improper_list(integer(), atom()))}
737749

738750
# The tail of either a (non empty) list of integers with an atom tail or a (non empty) list
739751
# of tuples with a float tail is either an atom, or a float, or a (possibly empty) list of
740752
# integers with an atom tail, or a (possibly empty) list of tuples with a float tail.
741-
assert list_tl(union(non_empty_list(integer(), atom()), non_empty_list(tuple(), float()))) ==
753+
assert list_tl(
754+
union(
755+
non_empty_maybe_improper_list(integer(), atom()),
756+
non_empty_maybe_improper_list(tuple(), float())
757+
)
758+
) ==
742759
{false,
743760
atom()
744761
|> union(float())
745762
|> union(
746-
union(non_empty_list(integer(), atom()), non_empty_list(tuple(), float()))
763+
union(
764+
non_empty_maybe_improper_list(integer(), atom()),
765+
non_empty_maybe_improper_list(tuple(), float())
766+
)
747767
)}
748768

749769
assert list_tl(dynamic()) == {true, dynamic()}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ defmodule Module.Types.ExprTest do
3636
describe "lists" do
3737
test "creating lists" do
3838
assert typecheck!([1, 2]) == non_empty_list(integer())
39-
assert typecheck!([1, 2 | 3]) == non_empty_list(integer(), integer())
39+
assert typecheck!([1, 2 | 3]) == non_empty_maybe_improper_list(integer(), integer())
4040
assert typecheck!([1, 2 | [3, 4]]) == non_empty_list(integer())
4141

4242
assert typecheck!([:ok, 123]) == non_empty_list(union(atom([:ok]), integer()))
43-
assert typecheck!([:ok | 123]) == non_empty_list(atom([:ok]), integer())
43+
assert typecheck!([:ok | 123]) == non_empty_maybe_improper_list(atom([:ok]), integer())
4444
assert typecheck!([x], [:ok, x]) == dynamic(non_empty_list(term()))
45-
assert typecheck!([x], [:ok | x]) == dynamic(non_empty_list(term(), term()))
45+
assert typecheck!([x], [:ok | x]) == dynamic(non_empty_maybe_improper_list(term(), term()))
4646
end
4747

4848
test "inference" do
@@ -94,7 +94,9 @@ defmodule Module.Types.ExprTest do
9494
assert typecheck!([x = [123, :foo]], tl(x)) == dynamic(list(union(atom([:foo]), integer())))
9595

9696
assert typecheck!([x = [123 | :foo]], tl(x)) ==
97-
dynamic(union(atom([:foo]), non_empty_list(integer(), atom([:foo]))))
97+
dynamic(
98+
union(atom([:foo]), non_empty_maybe_improper_list(integer(), atom([:foo])))
99+
)
98100

99101
assert typeerror!(tl([])) |> strip_ansi() ==
100102
~l"""

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ defmodule Module.Types.IntegrationTest do
208208
assert itself_arg.(Itself.Integer) == dynamic(integer())
209209

210210
assert itself_arg.(Itself.List) ==
211-
dynamic(union(empty_list(), non_empty_list(term(), term())))
211+
dynamic(union(empty_list(), non_empty_maybe_improper_list(term(), term())))
212212

213213
assert itself_arg.(Itself.Map) == dynamic(open_map(__struct__: if_set(negation(atom()))))
214214
assert itself_arg.(Itself.Port) == dynamic(port())
@@ -487,7 +487,7 @@ defmodule Module.Types.IntegrationTest do
487487
dynamic(
488488
%Date{} or %DateTime{} or %NaiveDateTime{} or %Time{} or %URI{} or %Version{} or
489489
%Version.Requirement{}
490-
) or atom() or binary() or empty_list() or float() or integer() or non_empty_list(term(), term())
490+
) or atom() or binary() or empty_list() or float() or integer() or non_empty_maybe_improper_list(term(), term())
491491
492492
where "data" was given the type:
493493
@@ -511,7 +511,7 @@ defmodule Module.Types.IntegrationTest do
511511
dynamic(
512512
%Date{} or %DateTime{} or %NaiveDateTime{} or %Time{} or %URI{} or %Version{} or
513513
%Version.Requirement{}
514-
) or atom() or binary() or empty_list() or float() or integer() or non_empty_list(term(), term())
514+
) or atom() or binary() or empty_list() or float() or integer() or non_empty_maybe_improper_list(term(), term())
515515
516516
where "data" was given the type:
517517
@@ -551,7 +551,7 @@ defmodule Module.Types.IntegrationTest do
551551
dynamic(
552552
%Date.Range{} or %File.Stream{} or %GenEvent.Stream{} or %HashDict{} or %HashSet{} or
553553
%IO.Stream{} or %MapSet{} or %Range{} or %Stream{}
554-
) or empty_list() or fun() or non_empty_list(term(), term()) or non_struct_map()
554+
) or empty_list() or fun() or non_empty_maybe_improper_list(term(), term()) or non_struct_map()
555555
556556
where "date" was given the type:
557557
@@ -580,7 +580,7 @@ defmodule Module.Types.IntegrationTest do
580580
but expected a type that implements the Collectable protocol, it must be one of:
581581
582582
dynamic(%File.Stream{} or %HashDict{} or %HashSet{} or %IO.Stream{} or %MapSet{}) or binary() or
583-
empty_list() or non_empty_list(term(), term()) or non_struct_map()
583+
empty_list() or non_empty_maybe_improper_list(term(), term()) or non_struct_map()
584584
585585
hint: the :into option in for-comprehensions use the Collectable protocol to build its result. Either pass a valid data type or implement the protocol accordingly
586586
"""

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,16 @@ defmodule Module.Types.PatternTest do
213213
dynamic(non_empty_list(integer()))
214214

215215
assert typecheck!([x = [1, 2, 3 | y], y = :foo], x) ==
216-
dynamic(non_empty_list(integer(), atom([:foo])))
216+
dynamic(non_empty_maybe_improper_list(integer(), atom([:foo])))
217217

218218
assert typecheck!([x = [1, 2, 3 | y], y = [1.0, 2.0, 3.0]], x) ==
219219
dynamic(non_empty_list(union(integer(), float())))
220220

221221
assert typecheck!([x = [:ok | z]], {x, z}) ==
222-
dynamic(tuple([non_empty_list(term(), term()), term()]))
222+
dynamic(tuple([non_empty_maybe_improper_list(term(), term()), term()]))
223223

224224
assert typecheck!([x = [y | z]], {x, y, z}) ==
225-
dynamic(tuple([non_empty_list(term(), term()), term(), term()]))
225+
dynamic(tuple([non_empty_maybe_improper_list(term(), term()), term(), term()]))
226226
end
227227

228228
test "in patterns through ++" do
@@ -232,7 +232,7 @@ defmodule Module.Types.PatternTest do
232232
dynamic(atom([:foo]))
233233

234234
assert typecheck!([x = [1, 2, 3] ++ y, y = :foo], x) ==
235-
dynamic(non_empty_list(integer(), atom([:foo])))
235+
dynamic(non_empty_maybe_improper_list(integer(), atom([:foo])))
236236

237237
assert typecheck!([x = [1, 2, 3] ++ y, y = [1.0, 2.0, 3.0]], x) ==
238238
dynamic(non_empty_list(union(integer(), float())))

0 commit comments

Comments
 (0)