Skip to content

Commit e5f9dbd

Browse files
author
José Valim
committed
Ensure Enum.to_list and Dict.to_list return the same results for dicts
1 parent f5b0b71 commit e5f9dbd

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* enhancements
44

55
* bug fix
6+
* [Dict] `Enum.to_list` and `Dict.to_list` now return the same results for dicts
67
* [Mix] Fix a bug where `mix deps.get` was not retrieving nested dependencies
78

89
* deprecations

lib/elixir/lib/hash_dict.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ defmodule HashDict do
246246
end
247247

248248
def to_list(dict) do
249-
dict_fold(dict, [], [&1|&2])
249+
dict_fold(dict, [], [&1|&2]) |> :lists.reverse
250250
end
251251

252252
@doc """

lib/elixir/test/elixir/hash_dict_test.exs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,23 @@ defmodule HashDictTest do
8585
end
8686

8787
test :to_list do
88-
list = filled_dict(8) |> HashDict.to_list
88+
dict = filled_dict(8)
89+
list = dict |> HashDict.to_list
8990
assert length(list) == 8
9091
assert { 1, 1 } in list
92+
assert list == Enum.to_list(dict)
9193

92-
list = filled_dict(20) |> HashDict.to_list
94+
dict = filled_dict(20)
95+
list = dict |> HashDict.to_list
9396
assert length(list) == 20
9497
assert { 1, 1 } in list
98+
assert list == Enum.to_list(dict)
9599

96-
list = filled_dict(120) |> HashDict.to_list
100+
dict = filled_dict(120)
101+
list = dict |> HashDict.to_list
97102
assert length(list) == 120
98103
assert { 1, 1 } in list
104+
assert list == Enum.to_list(dict)
99105
end
100106

101107
test :keys do

0 commit comments

Comments
 (0)