Skip to content

Commit 47079bc

Browse files
committed
Add more deprecations scheduled to v1.18
1 parent 19406b1 commit 47079bc

File tree

5 files changed

+48
-17
lines changed

5 files changed

+48
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ This release no longer supports WERL (a graphical user interface for the Erlang
1717
* [EEx] `<%#` is deprecated in favor of `<%!--` or `<% #`
1818
* [EEx] `c:EEx.handle_text/2` is deprecated in favor of `c:EEx.handle_text/3`
1919

20+
#### Elixir
21+
22+
* [Enumerable] Deprecate returning a two-arity function in `Enumerable.slice/1`
23+
* [Range] Deprecate inferring negative ranges on `Range.new/2`
24+
2025
#### Mix
2126

2227
* [mix cmd] Deprecate `mix cmd --app APP` in favor of `mix do --app APP`

lib/elixir/lib/enum.ex

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,13 +2416,17 @@ defmodule Enum do
24162416
{:ok, count, fun} when is_function(fun, 1) ->
24172417
slice_list(fun.(enumerable), random_count(count), 1, 1)
24182418

2419-
# TODO: Deprecate me in Elixir v1.18.
2420-
{:ok, count, fun} when is_function(fun, 2) ->
2421-
fun.(random_count(count), 1)
2422-
24232419
{:ok, count, fun} when is_function(fun, 3) ->
24242420
fun.(random_count(count), 1, 1)
24252421

2422+
# TODO: Remove deprecation on Elixir v1.20.
2423+
{:ok, count, fun} when is_function(fun, 2) ->
2424+
IO.warn(
2425+
"#{inspect(Enumerable.impl_for(enumerable))} must return a three arity function on slice/1"
2426+
)
2427+
2428+
fun.(random_count(count), 1)
2429+
24262430
{:error, _} ->
24272431
take_random(enumerable, 1)
24282432
end
@@ -4492,8 +4496,16 @@ defmodule Enum do
44924496
amount = Kernel.min(amount, count - start) |> amount_with_step(step)
44934497
enumerable |> fun.() |> slice_exact(start, amount, step, count)
44944498

4495-
# TODO: Deprecate me in Elixir v1.18.
4499+
{:ok, count, fun} when is_function(fun, 3) ->
4500+
amount = Kernel.min(amount, count - start) |> amount_with_step(step)
4501+
fun.(start, amount, step)
4502+
4503+
# TODO: Remove me on v2.0.
44964504
{:ok, count, fun} when is_function(fun, 2) ->
4505+
IO.warn(
4506+
"#{inspect(Enumerable.impl_for(enumerable))} must return a three arity function on slice/1"
4507+
)
4508+
44974509
amount = Kernel.min(amount, count - start)
44984510

44994511
if step == 1 do
@@ -4503,10 +4515,6 @@ defmodule Enum do
45034515
|> take_every_list(amount, step - 1)
45044516
end
45054517

4506-
{:ok, count, fun} when is_function(fun, 3) ->
4507-
amount = Kernel.min(amount, count - start) |> amount_with_step(step)
4508-
fun.(start, amount, step)
4509-
45104518
{:error, module} ->
45114519
slice_enum(enumerable, module, start, amount, step)
45124520
end
@@ -4565,11 +4573,18 @@ defmodule Enum do
45654573

45664574
defp slice_count_and_fun(enumerable, step) do
45674575
case Enumerable.slice(enumerable) do
4576+
{:ok, count, fun} when is_function(fun, 1) ->
4577+
{count, &slice_exact(fun.(enumerable), &1, &2, &3, count)}
4578+
45684579
{:ok, count, fun} when is_function(fun, 3) ->
45694580
{count, fun}
45704581

4571-
# TODO: Deprecate me in Elixir v1.18.
4582+
# TODO: Remove me on v2.0
45724583
{:ok, count, fun} when is_function(fun, 2) ->
4584+
IO.warn(
4585+
"#{inspect(Enumerable.impl_for(enumerable))} must return a three arity function on slice/1"
4586+
)
4587+
45734588
if step == 1 do
45744589
{count, fn start, amount, 1 -> fun.(start, amount) end}
45754590
else
@@ -4580,9 +4595,6 @@ defmodule Enum do
45804595
end}
45814596
end
45824597

4583-
{:ok, count, fun} when is_function(fun, 1) ->
4584-
{count, &slice_exact(fun.(enumerable), &1, &2, &3, count)}
4585-
45864598
{:error, module} ->
45874599
{list, count} =
45884600
enumerable

lib/elixir/lib/module/behaviour.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ defmodule Module.Behaviour do
144144
end
145145

146146
defp impl_behaviours({function, arity}, defaults, kind, value, behaviours, callbacks) do
147-
impls = for n <- arity..(arity - defaults), do: {function, n}
147+
impls = for n <- (arity - defaults)..arity, do: {function, n}
148148
impl_behaviours(impls, kind, value, behaviours, callbacks)
149149
end
150150

lib/elixir/lib/range.ex

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,22 @@ defmodule Range do
184184

185185
@spec new(limit, limit) :: t
186186
def new(first, last) when is_integer(first) and is_integer(last) do
187-
# TODO: Deprecate inferring a range with a step of -1 on Elixir v1.18
188-
step = if first <= last, do: 1, else: -1
187+
step =
188+
if first <= last do
189+
1
190+
else
191+
# TODO: Remove me on v2.0
192+
IO.warn_once(
193+
{__MODULE__, :new},
194+
fn ->
195+
"Range.new/2 has a default step of -1, please call Range.new/3 explicitly passing the step of -1 instead"
196+
end,
197+
3
198+
)
199+
200+
-1
201+
end
202+
189203
%Range{first: first, last: last, step: step}
190204
end
191205

lib/elixir/unicode/tokenizer.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ defmodule String.Tokenizer do
4242
case name do
4343
"<" <> _ when is_integer(first) ->
4444
last = String.to_integer(codepoint, 16)
45-
{Enum.to_list(last..first), nil}
45+
{Enum.to_list(last..first//-1), nil}
4646

4747
"<" <> _ ->
4848
first = String.to_integer(codepoint, 16)

0 commit comments

Comments
 (0)