diff --git a/lib/elixir/lib/kernel.ex b/lib/elixir/lib/kernel.ex index 31a9a4c8c6..0a9d013765 100644 --- a/lib/elixir/lib/kernel.ex +++ b/lib/elixir/lib/kernel.ex @@ -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)) @@ -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)) diff --git a/lib/elixir/test/elixir/kernel_test.exs b/lib/elixir/test/elixir/kernel_test.exs index bae0550e3b..fa4b7364a1 100644 --- a/lib/elixir/test/elixir/kernel_test.exs +++ b/lib/elixir/test/elixir/kernel_test.exs @@ -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}}}