Skip to content

Commit 0e671f4

Browse files
committed
Fix missing require using required: true meta
1 parent 4012cd0 commit 0e671f4

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

lib/elixir/lib/regex.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,9 +1021,10 @@ defmodule Regex do
10211021
{:ok, exported} = :re.compile(regex.source, [:export] ++ regex.opts)
10221022

10231023
quote do
1024-
require Regex
10251024
Regex.__import_pattern__(unquote(Macro.escape(exported)))
10261025
end
1026+
# we now that the Regex module is defined at this stage, so this macro can be safely called
1027+
|> Macro.update_meta(&([required: true] ++ &1))
10271028

10281029
# TODO: Remove this when we require Erlang/OTP 28.1+
10291030
# OTP 28.0 works in degraded mode performance-wise, we need to recompile from the source
@@ -1049,7 +1050,7 @@ defmodule Regex do
10491050
@doc false
10501051
defmacro __import_pattern__(pattern) do
10511052
if __CALLER__.context in [:match, :guard] do
1052-
raise ArgumentError, "escaped"
1053+
raise ArgumentError, "escaped Regex structs are not allowed in match or guards"
10531054
end
10541055

10551056
quote do

lib/elixir/test/elixir/macro_test.exs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,9 @@ defmodule MacroTest do
167167
[],
168168
[
169169
__struct__: Regex,
170-
re_pattern: {
171-
:__block__,
172-
[],
173-
[
174-
{:__assert_assert_no_match_or_guard_scope__, _, _},
175-
{{:., [], [:re, :import]}, [], [{:{}, [], [:re_exported_pattern | _]}]}
176-
]
177-
},
170+
re_pattern:
171+
{{:., [], [{:__aliases__, _, [:Regex]}, :__import_pattern__]},
172+
[required: true], [{:{}, [], [:re_exported_pattern | _]}]},
178173
source: "foo",
179174
opts: []
180175
]

lib/elixir/test/elixir/regex_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ defmodule RegexTest do
3232
test "module attribute in match context" do
3333
assert_raise(
3434
ArgumentError,
35-
~r/invalid expression in match, an escaped Regex is not allowed in patterns such as function clauses/,
35+
~r/escaped Regex structs are not allowed in match or guards/,
3636
fn ->
3737
Code.eval_quoted(
3838
quote do

0 commit comments

Comments
 (0)