Closed
Description
Elixir and Erlang/OTP versions
Erlang/OTP 27 [erts-15.2.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]
Elixir 1.19.0-dev (8b79681) (compiled with Erlang/OTP 27)
Operating system
MacOS
Current behavior
✅ When a regex is stored in a module attribute and used in a function body, a warning it emitted.
❌ When it's stored in a list, map, or anything, nothing is being emitted.
defmodule Foo do
@regex ~r/hello/
@list_regex [~r/hello/, ~r/world/]
def use do
Regex.match?(@regex, "use")
Enum.any?(@list_regex, &Regex.match?(&1, "use"))
end
end
# only the first @ emits
warning: storing and reading regexes from module attributes is deprecated, inline the regex inside the function definition instead
└─ iex:6: Foo.use/0
Expected behavior
I would have expected all regexes placed in module attributes to emit a warning, as, as far as I understand, those in arrays will cause an issue in OTP 28 too.
I see the warning is emitted when the module attribute is used, which may explain why it does not occur for lists or maps of regexes. Should it be moved to the module attribute declaration?
Metadata
Metadata
Assignees
Labels
No labels