From 512401f27f291e3a714797a31f638a1d6001dd2d Mon Sep 17 00:00:00 2001 From: Yves Orton Date: Tue, 11 Mar 2025 20:30:12 +0100 Subject: [PATCH] types.ex - improve warning message about defp defaults to mention private functions The original version of this warning did not mention that the warning applies to private functions only, this patch fixes that. --- lib/elixir/lib/module/types.ex | 8 +++++--- lib/elixir/test/elixir/kernel/warning_test.exs | 14 ++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/elixir/lib/module/types.ex b/lib/elixir/lib/module/types.ex index 8442e0d2692..3917ecf1c0f 100644 --- a/lib/elixir/lib/module/types.ex +++ b/lib/elixir/lib/module/types.ex @@ -464,14 +464,16 @@ defmodule Module.Types do ## Module errors def format_error({:unused_args, {name, arity}}), - do: "default values for the optional arguments in #{name}/#{arity} are never used" + do: + "default values for the optional arguments in the private function #{name}/#{arity} are never used" def format_error({:unused_args, {name, arity}, count}) when arity - count == 1, - do: "the default value for the last optional argument in #{name}/#{arity} is never used" + do: + "the default value for the last optional argument in the private function #{name}/#{arity} is never used" def format_error({:unused_args, {name, arity}, count}), do: - "the default values for the last #{arity - count} optional arguments in #{name}/#{arity} are never used" + "the default values for the last #{arity - count} optional arguments in the private function #{name}/#{arity} are never used" def format_error({:unused_def, {name, arity}, :defp}), do: "function #{name}/#{arity} is unused" diff --git a/lib/elixir/test/elixir/kernel/warning_test.exs b/lib/elixir/test/elixir/kernel/warning_test.exs index ff02ab98798..f118456f9d0 100644 --- a/lib/elixir/test/elixir/kernel/warning_test.exs +++ b/lib/elixir/test/elixir/kernel/warning_test.exs @@ -716,7 +716,10 @@ defmodule Kernel.WarningTest do test "unused default args" do assert_warn_eval( - ["nofile:3:8: ", "default values for the optional arguments in b/3 are never used"], + [ + "nofile:3:8: ", + "default values for the optional arguments in the private function b/3 are never used" + ], ~S""" defmodule Sample1 do def a, do: b(1, 2, 3) @@ -728,7 +731,7 @@ defmodule Kernel.WarningTest do assert_warn_eval( [ "nofile:3:8: ", - "the default value for the last optional argument in b/3 is never used" + "the default value for the last optional argument in the private function b/3 is never used" ], ~S""" defmodule Sample2 do @@ -741,7 +744,7 @@ defmodule Kernel.WarningTest do assert_warn_eval( [ "nofile:3:8: ", - "the default values for the last 2 optional arguments in b/4 are never used" + "the default values for the last 2 optional arguments in the private function b/4 are never used" ], ~S""" defmodule Sample3 do @@ -759,7 +762,10 @@ defmodule Kernel.WarningTest do """) == "" assert_warn_eval( - ["nofile:3:8: ", "the default value for the last optional argument in b/3 is never used"], + [ + "nofile:3:8: ", + "the default value for the last optional argument in the private function b/3 is never used" + ], ~S""" defmodule Sample5 do def a, do: b(1, 2)