summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@dashbit.co>2021-12-09 21:22:39 +0100
committerJosé Valim <jose.valim@dashbit.co>2021-12-09 21:22:39 +0100
commite89bbdfb2980d72a90127e42f078691fcbccdf59 (patch)
tree51e2f0e57968837fd3788ee9a9da49f3be98918c
parent20a5050b3528621354038159fa52b6135b1b53c9 (diff)
downloadelixir-e89bbdfb2980d72a90127e42f078691fcbccdf59.tar.gz
Handle improper lists on apply, closes #11465
-rw-r--r--lib/elixir/lib/exception.ex11
-rw-r--r--lib/elixir/test/elixir/exception_test.exs6
2 files changed, 12 insertions, 5 deletions
diff --git a/lib/elixir/lib/exception.ex b/lib/elixir/lib/exception.ex
index 7a0c5b028..1ee8fc425 100644
--- a/lib/elixir/lib/exception.ex
+++ b/lib/elixir/lib/exception.ex
@@ -732,6 +732,10 @@ defmodule ArgumentError do
) do
message =
cond do
+ not proper_list?(args) ->
+ "you attempted to apply a function named #{inspect(function)} on module #{inspect(module)} " <>
+ "with arguments #{inspect(args)}. Arguments (the third argument of apply) must always be a proper list"
+
# Note that args may be an empty list even if they were supplied
not is_atom(module) and is_atom(function) and args == [] ->
"you attempted to apply a function named #{inspect(function)} on #{inspect(module)}. " <>
@@ -747,10 +751,6 @@ defmodule ArgumentError do
"you attempted to apply a function named #{inspect(function)} on module #{inspect(module)}. " <>
"However #{inspect(function)} is not a valid function name. Function names (the second argument " <>
"of apply) must always be an atom"
-
- not is_list(args) ->
- "you attempted to apply a function named #{inspect(function)} on module #{inspect(module)} " <>
- "with arguments #{inspect(args)}. Arguments (the third argument of apply) must always be a list"
end
{%{exception | message: message}, stacktrace}
@@ -759,6 +759,9 @@ defmodule ArgumentError do
def blame(exception, stacktrace) do
{exception, stacktrace}
end
+
+ defp proper_list?(list) when length(list) >= 0, do: true
+ defp proper_list?(_), do: false
end
defmodule ArithmeticError do
diff --git a/lib/elixir/test/elixir/exception_test.exs b/lib/elixir/test/elixir/exception_test.exs
index 0e7090eb9..ab4520965 100644
--- a/lib/elixir/test/elixir/exception_test.exs
+++ b/lib/elixir/test/elixir/exception_test.exs
@@ -423,7 +423,11 @@ defmodule ExceptionTest do
assert blame_message(123, &apply(Kernel, :+, &1)) ==
"you attempted to apply a function named :+ on module Kernel with arguments 123. " <>
- "Arguments (the third argument of apply) must always be a list"
+ "Arguments (the third argument of apply) must always be a proper list"
+
+ assert blame_message(123, &apply(Kernel, :+, [&1 | 456])) ==
+ "you attempted to apply a function named :+ on module Kernel with arguments [123 | 456]. " <>
+ "Arguments (the third argument of apply) must always be a proper list"
end
test "annotates function clause errors" do