From 753ebf10354ac594abc3cd8fd7a9de43b25ad39b Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Wed, 22 Nov 2023 09:22:48 -0500 Subject: [PATCH] allow any pattern --- lib/ecto/query/builder/select.ex | 3 +-- test/ecto/query/builder/select_test.exs | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/ecto/query/builder/select.ex b/lib/ecto/query/builder/select.ex index 8de4d18851..8bb0c2b5ad 100644 --- a/lib/ecto/query/builder/select.ex +++ b/lib/ecto/query/builder/select.ex @@ -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 diff --git a/test/ecto/query/builder/select_test.exs b/test/ecto/query/builder/select_test.exs index 595dc055d2..476f084f63 100644 --- a/test/ecto/query/builder/select_test.exs +++ b/test/ecto/query/builder/select_test.exs @@ -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 @@ -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