Skip to content

Commit 9065839

Browse files
committed
Don't use Regex module inside Exception, as it may not be available
1 parent 3f30bf1 commit 9065839

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/elixir/lib/exception.ex

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,10 @@ defmodule Exception do
419419
end
420420

421421

422-
def function_name_pattern do
423-
%r{
422+
# have to use :re here because exceptions may be triggered before Regexp
423+
# module is compiled.
424+
@function_name_re :re.compile(
425+
%S{
424426
\A(
425427
[\w]+[?!]?
426428
| ->
@@ -449,15 +451,14 @@ defmodule Exception do
449451
| &
450452
| ~~~
451453
| @
452-
)\z}x
453-
end
454+
)\z}, [:extended] )
454455

455456
defp maybe_quote_name(fun) do
456457
name = to_string(fun)
457-
if Regex.match?(function_name_pattern, name) do
458-
name
459-
else
460-
inspect name
458+
{:ok, re} = @function_name_re
459+
case :re.run(name, re) do
460+
{ :match, _} -> name
461+
_ -> inspect name
461462
end
462463
end
463464

0 commit comments

Comments
 (0)