Skip to content

Commit

Permalink
Do not validate clauses of overridable functions, closes #14094
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Dec 22, 2024
1 parent 5882a52 commit fe089de
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/elixir/lib/module/types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,12 @@ defmodule Module.Types do
end

defp warn_unused_clauses(defs, stack, context) do
for {fun_arity, pending} <- context.local_used, pending != [], reduce: context do
for {fun_arity, pending} <- context.local_used,
pending != [],
{_fun_arity, kind, meta, clauses} = List.keyfind(defs, fun_arity, 0),
not Keyword.get(meta, :from_super, false),
reduce: context do
context ->
{_fun_arity, kind, _meta, clauses} = List.keyfind(defs, fun_arity, 0)
{_kind, _inferred, mapping} = Map.fetch!(context.local_sigs, fun_arity)

clauses_indexes =
Expand Down
3 changes: 2 additions & 1 deletion lib/elixir/src/elixir_overridable.erl
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ store_not_overridden(Module) ->
%% Private

store(Set, Module, Tuple, {_, Count, Def, Overridden}, Hidden) ->
{{{def, {Name, Arity}}, Kind, Meta, File, _Check,
{{{def, {Name, Arity}}, Kind, BaseMeta, File, _Check,
{Defaults, _HasBody, _LastDefaults}}, Clauses} = Def,
Meta = [{from_super, Hidden} | BaseMeta],

{FinalKind, FinalName, FinalArity, FinalClauses} =
case Hidden of
Expand Down
27 changes: 25 additions & 2 deletions lib/elixir/test/elixir/module/types/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,30 @@ defmodule Module.Types.IntegrationTest do
assert_warnings(files, warnings)
end

test "unused generated overridable private clauses" do
test "unused generated private clauses" do
files = %{
"a.ex" => """
defmodule A do
use B
def public(x), do: private(List.to_tuple(x))
end
""",
"b.ex" => """
defmodule B do
defmacro __using__(_) do
quote generated: true do
defp private({:ok, ok}), do: ok
defp private(:error), do: :error
end
end
end
"""
}

assert_no_warnings(files)
end

test "unused overridable private clauses" do
files = %{
"a.ex" => """
defmodule A do
Expand All @@ -208,7 +231,7 @@ defmodule Module.Types.IntegrationTest do
"b.ex" => """
defmodule B do
defmacro __using__(_) do
quote generated: true do
quote do
defp private({:ok, ok}), do: ok
defp private(:error), do: :error
defoverridable private: 1
Expand Down

0 comments on commit fe089de

Please sign in to comment.