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 authored Dec 12, 2024
1 parent 8a0cd66 commit a1938d4
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 @@ -3308,7 +3308,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 @@ -3329,7 +3329,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 a1938d4

Please sign in to comment.