Skip to content

Commit 89561c3

Browse files
author
José Valim
committed
Ensure defoverridable is not order dependant, closes #2615
1 parent d1b8657 commit 89561c3

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

lib/elixir/lib/module/locals_tracker.ex

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,9 @@ defmodule Module.LocalsTracker do
259259
end
260260

261261
def handle_call({:yank, local}, _from, {d, _} = state) do
262-
in_vertices = :digraph.in_neighbours(d, local)
263262
out_vertices = :digraph.out_neighbours(d, local)
264-
:digraph.del_vertex(d, local)
265-
{:reply, {in_vertices, out_vertices}, state}
263+
:digraph.del_edges(d, :digraph.out_edges(d, local))
264+
{:reply, {[], out_vertices}, state}
266265
end
267266

268267
def handle_call(:digraph, _from, {d, _} = state) do
@@ -300,9 +299,7 @@ defmodule Module.LocalsTracker do
300299
{:noreply, state}
301300
end
302301

303-
def handle_cast({:reattach, kind, tuple, {in_neigh, out_neigh}}, {d, _} = state) do
304-
handle_add_definition(d, kind, tuple)
305-
302+
def handle_cast({:reattach, _kind, tuple, {in_neigh, out_neigh}}, {d, _} = state) do
306303
for from <- in_neigh do
307304
:digraph.add_vertex(d, from)
308305
replace_edge!(d, from, tuple)

lib/elixir/test/elixir/kernel/overridable_test.exs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,27 @@ defmodule Kernel.Overridable do
9696
end
9797

9898
defmodule Kernel.OverridableTest do
99+
defmodule OverridableOrder do
100+
def not_private(str) do
101+
process_url(str)
102+
end
103+
104+
defp process_url(_str) do
105+
:first
106+
end
107+
108+
# There was a bug where the order in which we removed
109+
# overridable expressions lead to errors. This module
110+
# aims to guarantee removing process_url/1 before we
111+
# remove the function that depends on it does not cause
112+
# errors. If it compiles, it works!
113+
defoverridable [process_url: 1, not_private: 1]
114+
115+
defp process_url(_str) do
116+
:second
117+
end
118+
end
119+
99120
require Kernel.Overridable, as: Overridable
100121
use ExUnit.Case, async: true
101122

0 commit comments

Comments
 (0)