Skip to content

Commit

Permalink
Fix type warnings in pop_in/1 (#14064)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabiwara committed Dec 12, 2024
1 parent 55eca5d commit 6c866e8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/elixir/lib/kernel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3306,7 +3306,7 @@ defmodule Kernel do
end

defp nest_pop_in(:map, h, [{:access, key}]) do
quote do
quote generated: true do
case unquote(h) do
nil -> {nil, nil}
h -> Access.pop(h, unquote(key))
Expand All @@ -3327,7 +3327,7 @@ defmodule Kernel do
end

defp nest_pop_in(_, h, [{:access, key}]) do
quote do
quote generated: true do
case unquote(h) do
nil -> :pop
h -> Access.pop(h, unquote(key))
Expand Down
2 changes: 2 additions & 0 deletions lib/elixir/test/elixir/kernel_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,8 @@ defmodule KernelTest do
test "pop_in/1" do
users = %{"john" => %{age: 27}, "meg" => %{age: 23}}

assert pop_in(users["john"]) == {%{age: 27}, %{"meg" => %{age: 23}}}

assert pop_in(users["john"][:age]) == {27, %{"john" => %{}, "meg" => %{age: 23}}}
assert pop_in(users["john"][:name]) == {nil, %{"john" => %{age: 27}, "meg" => %{age: 23}}}
assert pop_in(users["bob"][:age]) == {nil, %{"john" => %{age: 27}, "meg" => %{age: 23}}}
Expand Down

0 comments on commit 6c866e8

Please sign in to comment.