Skip to content

Commit 286d310

Browse files
committed
Fixes for Erlang/OTP 23
1 parent 2fc9160 commit 286d310

File tree

6 files changed

+27
-40
lines changed

6 files changed

+27
-40
lines changed

lib/elixir/lib/map.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ defmodule Map do
265265
266266
iex> Map.fetch!(%{a: 1}, :a)
267267
1
268-
iex> Map.fetch!(%{a: 1}, :b)
269-
** (KeyError) key :b not found in: %{a: 1}
270268
271269
"""
272270
@spec fetch!(map, key) :: value

lib/elixir/src/elixir_erl.erl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,8 @@ definition_to_anonymous(Module, Kind, Meta, Clauses) ->
5454
{value, Result, _Binding} = erl_eval:expr(Fun, [], {value, LocalHandler}),
5555
Result.
5656

57-
invoke_local(Module, RawName, Args) ->
58-
%% If we have a macro, its arity in the table is
59-
%% actually one less than in the function call
60-
{Name, Arity} = case atom_to_list(RawName) of
61-
"MACRO-" ++ Rest -> {list_to_atom(Rest), length(Args) - 1};
62-
_ -> {RawName, length(Args)}
63-
end,
57+
invoke_local(Module, ErlName, Args) ->
58+
{Name, Arity} = elixir_utils:erl_fa_to_elixir_fa(ErlName, length(Args)),
6459

6560
case elixir_def:local_for(Module, Name, Arity, all) of
6661
false ->

lib/elixir/src/elixir_erl_compiler.erl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ custom_format(sys_core_fold, {eval_failure, Error}) ->
134134
#{'__struct__' := Struct} = 'Elixir.Exception':normalize(error, Error),
135135
["this expression will fail with ", elixir_aliases:inspect(Struct)];
136136

137+
custom_format(sys_core_fold, {nomatch_shadow,Line,{ErlName,ErlArity}}) ->
138+
{Name, Arity} = elixir_utils:erl_fa_to_elixir_fa(ErlName, ErlArity),
139+
140+
io_lib:format(
141+
"this clause for ~ts/~B cannot match because a previous clause at line ~B always matches",
142+
[Name, Arity, Line]
143+
);
144+
137145
custom_format([], Desc) ->
138146
io_lib:format("~p", [Desc]);
139147

lib/elixir/src/elixir_utils.erl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77
read_file_type/1, read_file_type/2, read_link_type/1, read_posix_mtime_and_size/1,
88
change_posix_time/2, change_universal_time/2,
99
guard_op/2, extract_splat_guards/1, extract_guards/1,
10-
erlang_comparison_op_to_elixir/1]).
10+
erlang_comparison_op_to_elixir/1, erl_fa_to_elixir_fa/2]).
1111
-include("elixir.hrl").
1212
-include_lib("kernel/include/file.hrl").
1313

14-
% Builds the macro name
15-
1614
macro_name(Macro) ->
1715
list_to_atom("MACRO-" ++ atom_to_list(Macro)).
1816

17+
erl_fa_to_elixir_fa(Name, Arity) ->
18+
case atom_to_list(Name) of
19+
"MACRO-" ++ Rest -> {list_to_atom(Rest), Arity - 1};
20+
_ -> {Name, Arity}
21+
end.
22+
1923
guard_op('andalso', 2) ->
2024
true;
2125
guard_op('orelse', 2) ->

lib/elixir/test/elixir/kernel/parallel_compiler_test.exs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ defmodule Kernel.ParallelCompilerTest do
288288
assert {:error, [error], []} =
289289
Kernel.ParallelCompiler.compile_to_path([fixture], output)
290290

291-
msg = "this clause cannot match because a previous clause at line 2 always matches"
292-
assert error == {fixture, 3, msg}
291+
assert {^fixture, 3, "this clause " <> _} = error
293292
end)
294293

295294
assert msg =~
@@ -434,10 +433,7 @@ defmodule Kernel.ParallelCompilerTest do
434433
capture_io(:stderr, fn ->
435434
assert {:error, [error], []} = Kernel.ParallelCompiler.require([fixture])
436435

437-
message =
438-
"this clause cannot match because a previous clause at line 2 always matches"
439-
440-
assert error == {fixture, 3, message}
436+
assert {^fixture, 3, "this clause " <> _} = error
441437
end)
442438

443439
assert msg =~

lib/elixir/test/elixir/kernel/warning_test.exs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -661,24 +661,6 @@ defmodule Kernel.WarningTest do
661661
purge(Sample)
662662
end
663663

664-
test "previous clause always matches" do
665-
assert capture_err(fn ->
666-
Code.eval_string("""
667-
defmodule Sample do
668-
def binary_cond do
669-
v = "bc"
670-
cond do
671-
is_binary(v) -> :bin
672-
true -> :ok
673-
end
674-
end
675-
end
676-
""")
677-
end) =~ "this clause cannot match because a previous clause at line 5 always matches"
678-
after
679-
purge(Sample)
680-
end
681-
682664
test "late function heads" do
683665
assert capture_err(fn ->
684666
Code.eval_string("""
@@ -740,7 +722,8 @@ defmodule Kernel.WarningTest do
740722
def hello, do: nil
741723
end
742724
""")
743-
end) =~ "this clause cannot match because a previous clause at line 2 always matches"
725+
end) =~
726+
~r"this clause( for hello/0)? cannot match because a previous clause at line 2 always matches"
744727
after
745728
purge(Sample)
746729
end
@@ -760,7 +743,8 @@ defmodule Kernel.WarningTest do
760743
use Sample
761744
end
762745
""")
763-
end) =~ "this clause cannot match because a previous clause at line 10 always matches"
746+
end) =~
747+
~r"this clause( for hello/0)? cannot match because a previous clause at line 10 always matches"
764748
after
765749
purge(Sample)
766750
purge(UseSample)
@@ -1628,7 +1612,8 @@ defmodule Kernel.WarningTest do
16281612
defguard foo(baz) when baz == :baz
16291613
end
16301614
""")
1631-
end) =~ "this clause cannot match because a previous clause at line 2 always matches"
1615+
end) =~
1616+
~r"this clause( for foo/1)? cannot match because a previous clause at line 2 always matches"
16321617
after
16331618
purge(Sample)
16341619
end
@@ -1641,7 +1626,8 @@ defmodule Kernel.WarningTest do
16411626
defmacro foo(bar), do: bar == :bar
16421627
end
16431628
""")
1644-
end) =~ "this clause cannot match because a previous clause at line 2 always matches"
1629+
end) =~
1630+
~r"this clause( for foo/1)? cannot match because a previous clause at line 2 always matches"
16451631
after
16461632
purge(Sample)
16471633
end

0 commit comments

Comments
 (0)