Skip to content

Commit

Permalink
allow any pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-rychlewski committed Nov 22, 2023
1 parent c608a0e commit 753ebf1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/ecto/query/builder/select.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ defmodule Ecto.Query.Builder.Select do
{k, params_acc}
end

defp escape_key({:^, _, [{var, _, context} = k]}, params_acc, _vars, _env)
when is_atom(var) and is_atom(context) do
defp escape_key({:^, _, [k]}, params_acc, _vars, _env) do
{k, params_acc}
end

Expand Down
11 changes: 11 additions & 0 deletions test/ecto/query/builder/select_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,12 @@ defmodule Ecto.Query.Builder.SelectTest do

test "supports interpolated map keys" do
key = :test_key

q = from p in "posts", select: %{^key => 1}
assert {:%{}, [], [test_key: 1]} = q.select.expr

q = from p in "posts", select: %{^:test_key => 1}
assert {:%{}, [], [test_key: 1]} = q.select.expr
end
end

Expand Down Expand Up @@ -689,6 +693,13 @@ defmodule Ecto.Query.Builder.SelectTest do
select_merge: %{^shared_key => :new, ^merge_key => :merge}

assert {:%{}, [], [shared: :new, merge: :merge]} = q.select.expr

q =
from p in "posts",
select: %{^:shared => :old},
select_merge: %{^:shared => :new, ^:merge => :merge}

assert {:%{}, [], [shared: :new, merge: :merge]} = q.select.expr
end
end
end

0 comments on commit 753ebf1

Please sign in to comment.