Skip to content

Commit c1e79d1

Browse files
committed
Support Erlang/OTP 28
1 parent d800e9c commit c1e79d1

File tree

8 files changed

+34
-182
lines changed

8 files changed

+34
-182
lines changed

lib/elixir/lib/regex.ex

Lines changed: 23 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ defmodule Regex do
188188
check and recompile the regex if necessary.
189189
"""
190190

191-
defstruct re_pattern: nil, source: "", opts: [], re_version: ""
191+
defstruct re_pattern: nil, source: "", opts: []
192192

193193
@type t :: %__MODULE__{re_pattern: term, source: binary, opts: binary | [term]}
194194

@@ -213,38 +213,35 @@ defmodule Regex do
213213
214214
## Examples
215215
216-
iex> Regex.compile("foo")
217-
{:ok, ~r/foo/}
216+
Regex.compile("foo")
217+
#=> {:ok, ~r/foo/}
218218
219-
iex> Regex.compile("*foo")
220-
{:error, {~c"nothing to repeat", 0}}
219+
Regex.compile("foo", "i")
220+
#=> {:ok, ~r/foo/i}
221221
222-
iex> Regex.compile("foo", "i")
223-
{:ok, ~r/foo/i}
224-
225-
iex> Regex.compile("foo", [:caseless])
226-
{:ok, Regex.compile!("foo", [:caseless])}
222+
Regex.compile("*foo")
223+
#=> {:error, {~c"quantifier does not follow a repeatable item", 0}}
227224
228225
"""
229226
@spec compile(binary, binary | [term]) :: {:ok, t} | {:error, term}
230227
def compile(source, opts \\ "") when is_binary(source) do
231-
compile(source, opts, version())
228+
do_compile(source, opts)
232229
end
233230

234-
defp compile(source, opts, version) when is_binary(opts) do
231+
defp do_compile(source, opts) when is_binary(opts) do
235232
case translate_options(opts, []) do
236233
{:error, rest} ->
237234
{:error, {:invalid_option, rest}}
238235

239236
translated_opts ->
240-
compile(source, translated_opts, version)
237+
do_compile(source, translated_opts)
241238
end
242239
end
243240

244-
defp compile(source, opts, version) when is_list(opts) do
241+
defp do_compile(source, opts) when is_list(opts) do
245242
case :re.compile(source, opts) do
246243
{:ok, re_pattern} ->
247-
{:ok, %Regex{re_pattern: re_pattern, re_version: version, source: source, opts: opts}}
244+
{:ok, %Regex{re_pattern: re_pattern, source: source, opts: opts}}
248245

249246
error ->
250247
error
@@ -268,38 +265,29 @@ defmodule Regex do
268265
This checks the version stored in the regular expression
269266
and recompiles the regex in case of version mismatch.
270267
"""
268+
# Remove me on Elixir v1.22
269+
@doc deprecated: "It can be removed and it has no effect"
271270
@doc since: "1.4.0"
272-
@spec recompile(t) :: {:ok, t} | {:error, any}
273271
def recompile(%Regex{} = regex) do
274-
version = version()
275-
276-
case regex do
277-
%{re_version: ^version} ->
278-
{:ok, regex}
279-
280-
_ ->
281-
%{source: source, opts: opts} = regex
282-
compile(source, opts, version)
283-
end
272+
{:ok, regex}
284273
end
285274

286275
@doc """
287276
Recompiles the existing regular expression and raises `Regex.CompileError` in case of errors.
288277
"""
278+
# Remove me on Elixir v1.22
279+
@doc deprecated: "It can be removed and it has no effect"
289280
@doc since: "1.4.0"
290-
@spec recompile!(t) :: t
291281
def recompile!(regex) do
292-
case recompile(regex) do
293-
{:ok, regex} -> regex
294-
{:error, {reason, at}} -> raise Regex.CompileError, "#{reason} at position #{at}"
295-
end
282+
regex
296283
end
297284

298285
@doc """
299286
Returns the version of the underlying Regex engine.
300287
"""
288+
# Remove me on Elixir v1.22
289+
@doc deprecated: "Use :re.version() instead"
301290
@doc since: "1.4.0"
302-
@spec version :: term()
303291
def version do
304292
{:re.version(), :erlang.system_info(:endian)}
305293
end
@@ -455,17 +443,7 @@ defmodule Regex do
455443
456444
"""
457445
@spec names(t) :: [String.t()]
458-
def names(%Regex{re_pattern: compiled, re_version: version, source: source}) do
459-
re_pattern =
460-
case version() do
461-
^version ->
462-
compiled
463-
464-
_ ->
465-
{:ok, recompiled} = :re.compile(source)
466-
recompiled
467-
end
468-
446+
def names(%Regex{re_pattern: re_pattern}) do
469447
{:namelist, names} = :re.inspect(re_pattern, :namelist)
470448
names
471449
end
@@ -528,22 +506,8 @@ defmodule Regex do
528506
end
529507
end
530508

531-
defp safe_run(
532-
%Regex{re_pattern: compiled, source: source, re_version: version, opts: compile_opts},
533-
string,
534-
options
535-
) do
536-
case version() do
537-
^version ->
538-
:re.run(string, compiled, options)
539-
540-
_ when is_list(compile_opts) ->
541-
:re.run(string, source, compile_opts ++ options)
542-
543-
# TODO: This clause is kept for compatibility with previous Elixir versions. Remove on v2.0+.
544-
_ when is_binary(compile_opts) ->
545-
:re.run(string, source, translate_options(compile_opts, options))
546-
end
509+
defp safe_run(%Regex{re_pattern: re_pattern}, string, options) do
510+
:re.run(string, re_pattern, options)
547511
end
548512

549513
@doc """

lib/elixir/src/elixir_erl.erl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,12 @@ dynamic_form(#{module := Module, relative_file := RelativeFile,
171171
{Def, Defmacro, Macros, Exports, Functions} =
172172
split_definition(Definitions, Unreachable, Line, [], [], [], [], {[], []}),
173173

174-
FilteredOpts = lists:filter(fun({no_warn_undefined, _}) -> false; (_) -> true end, Opts),
174+
FilteredOpts = lists:filter(fun(
175+
{no_warn_undefined, _}) -> false;
176+
(debug_info) -> false;
177+
(_) -> true
178+
end, Opts),
179+
175180
Location = {elixir_utils:characters_to_list(RelativeFile), Line},
176181

177182
Prefix = [{attribute, Line, file, Location},

lib/elixir/test/elixir/fixtures/dialyzer/protocol_opaque.ex

Lines changed: 0 additions & 29 deletions
This file was deleted.

lib/elixir/test/elixir/kernel/dialyzer_test.exs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,6 @@ defmodule Kernel.DialyzerTest do
120120
assert_dialyze_no_warnings!(context)
121121
end
122122

123-
@tag warnings: [:specdiffs]
124-
test "no warnings on protocol calls with opaque types", context do
125-
alias Dialyzer.ProtocolOpaque
126-
127-
copy_beam!(context, ProtocolOpaque)
128-
copy_beam!(context, ProtocolOpaque.Entity)
129-
copy_beam!(context, ProtocolOpaque.Entity.Any)
130-
copy_beam!(context, ProtocolOpaque.Duck)
131-
assert_dialyze_no_warnings!(context)
132-
133-
# Also ensure no warnings after consolidation.
134-
Code.prepend_path(context.base_dir)
135-
{:ok, binary} = Protocol.consolidate(ProtocolOpaque.Entity, [ProtocolOpaque.Duck, Any])
136-
File.write!(Path.join(context.outdir, "#{ProtocolOpaque.Entity}.beam"), binary)
137-
assert_dialyze_no_warnings!(context)
138-
end
139-
140123
test "no warnings on and/2 and or/2", context do
141124
copy_beam!(context, Dialyzer.BooleanCheck)
142125
assert_dialyze_no_warnings!(context)

lib/elixir/test/elixir/option_parser_test.exs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,9 @@ end
432432
defmodule OptionsParserDeprecationsTest do
433433
use ExUnit.Case, async: true
434434

435-
@warning ~r[not passing the :switches or :strict option to OptionParser is deprecated]
436-
437435
def assert_deprecated(fun) do
438-
assert ExUnit.CaptureIO.capture_io(:stderr, fun) =~ @warning
436+
assert ExUnit.CaptureIO.capture_io(:stderr, fun) =~
437+
"not passing the :switches or :strict option to OptionParser is deprecated"
439438
end
440439

441440
test "parses boolean option" do

lib/elixir/test/elixir/regex_test.exs

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,6 @@ Code.require_file("test_helper.exs", __DIR__)
77
defmodule RegexTest do
88
use ExUnit.Case, async: true
99

10-
@re_21_3_little %Regex{
11-
re_pattern:
12-
{:re_pattern, 1, 0, 0,
13-
<<69, 82, 67, 80, 94, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255,
14-
255, 99, 0, 0, 0, 0, 0, 1, 0, 0, 0, 64, 0, 6, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
15-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 102, 111, 111, 0, 131, 0, 20, 29, 99, 133,
16-
0, 7, 0, 1, 29, 100, 119, 0, 5, 29, 101, 120, 0, 12, 120, 0, 20, 0>>},
17-
re_version: {"8.42 2018-03-20", :little},
18-
source: "c(?<foo>d|e)"
19-
}
20-
21-
@re_21_3_big %Regex{
22-
re_pattern:
23-
{:re_pattern, 1, 0, 0,
24-
<<80, 67, 82, 69, 0, 0, 0, 86, 0, 0, 0, 0, 0, 0, 0, 17, 255, 255, 255, 255, 255, 255, 255,
25-
255, 0, 99, 0, 0, 0, 0, 0, 1, 0, 0, 0, 56, 0, 6, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
26-
0, 0, 0, 0, 0, 0, 1, 102, 111, 111, 0, 131, 0, 20, 29, 99, 133, 0, 7, 0, 1, 29, 100, 119,
27-
0, 5, 29, 101, 120, 0, 12, 120, 0, 20, 0>>},
28-
re_version: {"8.42 2018-03-20", :big},
29-
source: "c(?<foo>d|e)"
30-
}
31-
32-
@re_19_3_little %Regex{
33-
re_pattern:
34-
{:re_pattern, 1, 0, 0,
35-
<<69, 82, 67, 80, 94, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255,
36-
255, 99, 0, 0, 0, 0, 0, 1, 0, 0, 0, 64, 0, 6, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
37-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 102, 111, 111, 0, 125, 0, 20, 29, 99, 127,
38-
0, 7, 0, 1, 29, 100, 113, 0, 5, 29, 101, 114, 0, 12, 114, 0, 20, 0>>},
39-
re_version: {"8.33 2013-05-29", :little},
40-
source: "c(?<foo>d|e)"
41-
}
42-
4310
doctest Regex
4411

4512
test "multiline" do
@@ -72,16 +39,9 @@ defmodule RegexTest do
7239
test "literal source" do
7340
assert Regex.source(Regex.compile!("foo")) == "foo"
7441
assert Regex.source(~r"foo") == "foo"
75-
assert Regex.re_pattern(Regex.compile!("foo")) == Regex.re_pattern(~r"foo")
7642

7743
assert Regex.source(Regex.compile!("\a\b\d\e\f\n\r\s\t\v")) == "\a\b\d\e\f\n\r\s\t\v"
7844
assert Regex.source(~r<\a\b\d\e\f\n\r\s\t\v>) == "\\a\\b\\d\\e\\f\\n\\r\\s\\t\\v"
79-
80-
assert Regex.re_pattern(Regex.compile!("\a\b\d\e\f\n\r\s\t\v")) ==
81-
Regex.re_pattern(~r"\x07\x08\x7F\x1B\x0C\x0A\x0D\x20\x09\x0B")
82-
83-
assert Regex.re_pattern(Regex.compile!("\\a\\b\\d\e\f\\n\\r\\s\\t\\v")) ==
84-
Regex.re_pattern(~r"\a\b\d\e\f\n\r\s\t\v")
8545
end
8646

8747
test "Unicode" do
@@ -120,16 +80,6 @@ defmodule RegexTest do
12080
end
12181
end
12282

123-
test "recompile/1" do
124-
new_regex = ~r/foo/
125-
{:ok, %Regex{}} = Regex.recompile(new_regex)
126-
assert %Regex{} = Regex.recompile!(new_regex)
127-
128-
old_regex = Map.delete(~r/foo/, :re_version)
129-
{:ok, %Regex{}} = Regex.recompile(old_regex)
130-
assert %Regex{} = Regex.recompile!(old_regex)
131-
end
132-
13383
test "opts/1" do
13484
assert Regex.opts(Regex.compile!("foo", "i")) == [:caseless]
13585
assert Regex.opts(Regex.compile!("foo", [:ucp])) == [:ucp]
@@ -183,16 +133,6 @@ defmodule RegexTest do
183133
assert Regex.run(~r"bar", "foobar", offset: 2, return: :index) == [{3, 3}]
184134
end
185135

186-
test "run/3 with regexes compiled in different systems" do
187-
assert Regex.run(@re_21_3_little, "abcd abce", capture: :all_names) == ["d"]
188-
assert Regex.run(@re_21_3_big, "abcd abce", capture: :all_names) == ["d"]
189-
assert Regex.run(@re_19_3_little, "abcd abce", capture: :all_names) == ["d"]
190-
end
191-
192-
test "run/3 with regexes with options compiled in different systems" do
193-
assert Regex.run(%{~r/foo/i | re_version: "bad version"}, "FOO") == ["FOO"]
194-
end
195-
196136
test "scan/2" do
197137
assert Regex.scan(~r"c(d|e)", "abcd abce") == [["cd", "d"], ["ce", "e"]]
198138
assert Regex.scan(~r"c(?:d|e)", "abcd abce") == [["cd"], ["ce"]]
@@ -211,16 +151,6 @@ defmodule RegexTest do
211151
assert Regex.scan(~r"^foo", "foobar", offset: 1) == []
212152
end
213153

214-
test "scan/2 with regexes compiled in different systems" do
215-
assert Regex.scan(@re_21_3_little, "abcd abce", capture: :all_names) == [["d"], ["e"]]
216-
assert Regex.scan(@re_21_3_big, "abcd abce", capture: :all_names) == [["d"], ["e"]]
217-
assert Regex.scan(@re_19_3_little, "abcd abce", capture: :all_names) == [["d"], ["e"]]
218-
end
219-
220-
test "scan/2 with regexes with options compiled in different systems" do
221-
assert Regex.scan(%{~r/foo/i | re_version: "bad version"}, "FOO") == [["FOO"]]
222-
end
223-
224154
test "split/2,3" do
225155
assert Regex.split(~r",", "") == [""]
226156
assert Regex.split(~r",", "", trim: true) == []

lib/ex_unit/test/ex_unit/assertions_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ defmodule ExUnit.AssertionsTest do
711711
rescue
712712
error in [ExUnit.AssertionError] ->
713713
"foo" = error.left
714-
~r{a} = error.right
714+
%Regex{} = error.right
715715
end
716716
end
717717

@@ -726,7 +726,7 @@ defmodule ExUnit.AssertionsTest do
726726
rescue
727727
error in [ExUnit.AssertionError] ->
728728
"foo" = error.left
729-
~r"o" = error.right
729+
%Regex{} = error.right
730730
end
731731
end
732732

lib/iex/test/iex/helpers_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ defmodule IEx.HelpersTest do
353353
assert captured =~ "-spec sleep(Time) -> ok when Time :: timeout()."
354354
else
355355
assert captured =~ "sleep(Time)"
356-
assert captured =~ "@spec sleep(time) :: :ok when time: timeout()"
356+
assert captured =~ "@spec sleep(time) :: :ok when time: "
357357
end
358358
end
359359

0 commit comments

Comments
 (0)