Skip to content

Commit 2eb4a9f

Browse files
som-snytttgodzik
authored andcommitted
Name the parameter using a default
[Cherry-picked 8ba7cd3]
1 parent b6acf37 commit 2eb4a9f

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

compiler/src/dotty/tools/dotc/transform/TailRec.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,11 @@ class TailRec extends MiniPhase {
325325

326326
if isRecursiveCall then
327327
if ctx.settings.Whas.recurseWithDefault then
328-
if tree.args.exists(_.symbol.name.is(DefaultGetterName)) then
329-
report.warning(RecurseWithDefault(), tree.srcPos)
328+
tree.args.find(_.symbol.name.is(DefaultGetterName)) match
329+
case Some(arg) =>
330+
val DefaultGetterName(_, index) = arg.symbol.name: @unchecked
331+
report.warning(RecurseWithDefault(calledMethod.info.firstParamNames(index)), tree.srcPos)
332+
case _ =>
330333

331334
if (inTailPosition) {
332335
tailrec.println("Rewriting tail recursive call: " + tree.span)

tests/warn/i23541.check

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- [E220] Type Warning: tests/warn/i23541.scala:29:13 ------------------------------------------------------------------
2+
29 | println(f(using s = "ab")) // warn uses default instead of given // prints "ab"
3+
| ^^^^^^^^^^^^^^^^^
4+
| Argument for implicit parameter i was supplied using a default argument.
5+
|
6+
| longer explanation available when compiling with `-explain`
7+
-- [E221] Type Warning: tests/warn/i23541.scala:5:17 -------------------------------------------------------------------
8+
5 | else fun(x - 1)(using p = p + x) // warn recurse uses default (instead of given passed down the stack)
9+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
| Recursive call used a default argument for parameter q.
11+
|
12+
| longer explanation available when compiling with `-explain`
13+
-- [E221] Type Warning: tests/warn/i23541.scala:9:17 -------------------------------------------------------------------
14+
9 | else gun(x - 1)(p = p + x) // warn recurse uses default (value not passed down the stack)
15+
| ^^^^^^^^^^^^^^^^^^^^^
16+
| Recursive call used a default argument for parameter q.
17+
|
18+
| longer explanation available when compiling with `-explain`

0 commit comments

Comments
 (0)