Skip to content

Commit 185689a

Browse files
sabiwarajosevalim
authored andcommitted
Fix infinite loop in Enum.take/2 (#12048)
1 parent 7554064 commit 185689a

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

lib/elixir/lib/range.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ defimpl Enumerable, for: Range do
425425
slice(Map.put(range, :step, step))
426426
end
427427

428-
defp slice(current, _step, 1), do: [current]
428+
defp slice(_current, _step, 0), do: []
429429
defp slice(current, step, remaining), do: [current | slice(current + step, step, remaining - 1)]
430430
end
431431

lib/elixir/test/elixir/enum_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,6 +2286,7 @@ defmodule EnumTest.Range do
22862286
assert Enum.take(1..3, -2) == [2, 3]
22872287
assert Enum.take(1..3, -4) == [1, 2, 3]
22882288
assert Enum.take(1..0, 3) == [1, 0]
2289+
assert Enum.take(1..0//1, -3) == []
22892290
end
22902291

22912292
test "take_every/2" do

0 commit comments

Comments
 (0)