Skip to content

Commit 529040c

Browse files
committed
Fix false positive for named args (and other)
- Fix the non-miniphase traverser - Update test cases
1 parent c4d63cc commit 529040c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,15 @@ class CheckUnused extends MiniPhase:
197197
case t:tpd.ValDef =>
198198
prepareForValDef(t)
199199
traverseChildren(tree)(using newCtx)
200+
transformValDef(t)
200201
case t:tpd.DefDef =>
201202
prepareForDefDef(t)
202203
traverseChildren(tree)(using newCtx)
204+
transformDefDef(t)
203205
case t:tpd.TypeDef =>
204206
prepareForTypeDef(t)
205207
traverseChildren(tree)(using newCtx)
208+
transformTypeDef(t)
206209
case t: tpd.Bind =>
207210
prepareForBind(t)
208211
traverseChildren(tree)(using newCtx)
@@ -325,7 +328,7 @@ object CheckUnused:
325328
* The optional name will be used to target the right import
326329
* as the same element can be imported with different renaming
327330
*/
328-
def registerUsed(sym: Symbol, name: Option[Name])(using Context): Unit =
331+
def registerUsed(sym: Symbol, name: Option[Name])(using Context): Unit =
329332
if !isConstructorOfSynth(sym) && !doNotRegister(sym) then
330333
if sym.isConstructor && sym.exists then
331334
registerUsed(sym.owner, None) // constructor are "implicitly" imported with the class
@@ -365,7 +368,7 @@ object CheckUnused:
365368
implicitParamInScope += memDef
366369
else
367370
explicitParamInScope += memDef
368-
else if currScopeType.top == ScopeType.Local then
371+
else if currScopeType.top == ScopeType.Local then
369372
localDefInScope += memDef
370373
else if currScopeType.top == ScopeType.Template && memDef.symbol.is(Private, butNot = SelfName) then
371374
privateDefInScope += memDef

tests/neg-custom-args/fatal-warnings/i15503i.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,14 @@ package foo.test.companionprivate:
7373

7474
object A:
7575
private def b = c // OK
76-
def c = List(1,2,3) // OK
76+
def c = List(1,2,3) // OK
77+
78+
package foo.test.i16678:
79+
def foo(func: Int => String, value: Int): String = func(value) // OK
80+
81+
def run =
82+
println(foo(number => number.toString, value = 5)) // OK
83+
println(foo(number => "<number>", value = 5)) // error
84+
println(foo(func = number => "<number>", value = 5)) // error
85+
println(foo(func = number => number.toString, value = 5)) // OK
86+
println(foo(func = _.toString, value = 5)) // OK

0 commit comments

Comments
 (0)