Skip to content

Commit d25bea5

Browse files
demerphqYves Orton
andauthored
Improve warning message about defaults to mention private functions (#14326)
The original version of this warning did not mention that the warning applies to private functions only, this patch fixes that. Co-authored-by: Yves Orton <yves.orton@remote.com>
1 parent d661840 commit d25bea5

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/elixir/lib/module/types.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,16 @@ defmodule Module.Types do
464464
## Module errors
465465

466466
def format_error({:unused_args, {name, arity}}),
467-
do: "default values for the optional arguments in #{name}/#{arity} are never used"
467+
do:
468+
"default values for the optional arguments in the private function #{name}/#{arity} are never used"
468469

469470
def format_error({:unused_args, {name, arity}, count}) when arity - count == 1,
470-
do: "the default value for the last optional argument in #{name}/#{arity} is never used"
471+
do:
472+
"the default value for the last optional argument in the private function #{name}/#{arity} is never used"
471473

472474
def format_error({:unused_args, {name, arity}, count}),
473475
do:
474-
"the default values for the last #{arity - count} optional arguments in #{name}/#{arity} are never used"
476+
"the default values for the last #{arity - count} optional arguments in the private function #{name}/#{arity} are never used"
475477

476478
def format_error({:unused_def, {name, arity}, :defp}),
477479
do: "function #{name}/#{arity} is unused"

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,10 @@ defmodule Kernel.WarningTest do
716716

717717
test "unused default args" do
718718
assert_warn_eval(
719-
["nofile:3:8: ", "default values for the optional arguments in b/3 are never used"],
719+
[
720+
"nofile:3:8: ",
721+
"default values for the optional arguments in the private function b/3 are never used"
722+
],
720723
~S"""
721724
defmodule Sample1 do
722725
def a, do: b(1, 2, 3)
@@ -728,7 +731,7 @@ defmodule Kernel.WarningTest do
728731
assert_warn_eval(
729732
[
730733
"nofile:3:8: ",
731-
"the default value for the last optional argument in b/3 is never used"
734+
"the default value for the last optional argument in the private function b/3 is never used"
732735
],
733736
~S"""
734737
defmodule Sample2 do
@@ -741,7 +744,7 @@ defmodule Kernel.WarningTest do
741744
assert_warn_eval(
742745
[
743746
"nofile:3:8: ",
744-
"the default values for the last 2 optional arguments in b/4 are never used"
747+
"the default values for the last 2 optional arguments in the private function b/4 are never used"
745748
],
746749
~S"""
747750
defmodule Sample3 do
@@ -759,7 +762,10 @@ defmodule Kernel.WarningTest do
759762
""") == ""
760763

761764
assert_warn_eval(
762-
["nofile:3:8: ", "the default value for the last optional argument in b/3 is never used"],
765+
[
766+
"nofile:3:8: ",
767+
"the default value for the last optional argument in the private function b/3 is never used"
768+
],
763769
~S"""
764770
defmodule Sample5 do
765771
def a, do: b(1, 2)

0 commit comments

Comments
 (0)