Skip to content

Commit 164d1d0

Browse files
author
José Valim
committed
Tighten guards in Exception to avoid false positives
1 parent e8c53a8 commit 164d1d0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/elixir/lib/exception.ex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ defmodule Exception do
579579
#=> "#Function<...>/1"
580580
581581
"""
582-
def format_fa(fun, arity) do
582+
def format_fa(fun, arity) when is_function(fun) do
583583
"#{inspect fun}#{format_arity(arity)}"
584584
end
585585

@@ -603,7 +603,7 @@ defmodule Exception do
603603
where func is the name of the enclosing function. Convert to
604604
"anonymous fn in func/arity"
605605
"""
606-
def format_mfa(module, fun, arity) when is_atom(fun) do
606+
def format_mfa(module, fun, arity) when is_atom(module) and is_atom(fun) do
607607
fun =
608608
case inspect(fun) do
609609
":" <> fun -> fun
@@ -623,7 +623,9 @@ defmodule Exception do
623623
"(#{Enum.join(inspected, ", ")})"
624624
end
625625

626-
defp format_arity(arity), do: "/#{arity}"
626+
defp format_arity(arity) when is_integer(arity) do
627+
"/" <> integer_to_binary(arity)
628+
end
627629

628630
@doc """
629631
Formats the given file and line as shown in stacktraces.
@@ -657,7 +659,7 @@ defmodule Exception do
657659
end
658660
end
659661

660-
defp format_location(opts) do
662+
defp format_location(opts) when is_list(opts) do
661663
format_file_line Keyword.get(opts, :file), Keyword.get(opts, :line), " "
662664
end
663665

0 commit comments

Comments
 (0)