Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/elixir/src/elixir_quote.erl
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,12 @@ tail_list(Left, Right, Tail) when is_list(Left) ->
[H | T] = lists:reverse(Tail ++ Left),
lists:reverse([{'|', [], [H, Right]} | T]).

validate_list(List) when is_list(List) ->
ok;
validate_list(List) when not is_list(List) ->
argument_error(<<"expected a list with quoted expressions in unquote_splicing/1, got: ",
('Elixir.Kernel':inspect(List))/binary>>).
validate_list(List) ->
case valid_ast_list(List) of
true -> ok;
false -> argument_error(<<"expected a list with quoted expressions in unquote_splicing/1, got: ",
('Elixir.Kernel':inspect(List))/binary>>)
end.

argument_error(Message) ->
error('Elixir.ArgumentError':exception([{message, Message}])).
Expand Down
19 changes: 19 additions & 0 deletions lib/elixir/test/elixir/kernel/quote_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -814,4 +814,23 @@ defmodule Kernel.QuoteTest.HasUnquoteTest do
assert quote do: unquote(foo: [1 | 2]) == [foo: [1 | 2]]
assert quote do: unquote(foo: [bar: %{}]) == [foo: [bar: %{}]]
end

test "unquote_splicing with invalid AST" do
for args <- [
"not_a_list",
[:improper | :list],
[%{unescaped: :map}],
[1..10],
[{:bad_meta, nil, []}],
[{:bad_arg, nil, 1}],
[{:bad_tuple}],
[make_ref()],
[nested: {}]
] do
message =
"expected a list with quoted expressions in unquote_splicing/1, got: #{inspect(args)}"

assert_raise ArgumentError, message, fn -> quote do: [unquote_splicing(args)] end
end
end
end
Loading