diff --git a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala index ef27e9c44daf..59878757c39b 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala @@ -204,12 +204,15 @@ class CheckUnused extends MiniPhase: case t:tpd.ValDef => prepareForValDef(t) traverseChildren(tree)(using newCtx) + transformValDef(t) case t:tpd.DefDef => prepareForDefDef(t) traverseChildren(tree)(using newCtx) + transformDefDef(t) case t:tpd.TypeDef => prepareForTypeDef(t) traverseChildren(tree)(using newCtx) + transformTypeDef(t) case t: tpd.Bind => prepareForBind(t) traverseChildren(tree)(using newCtx) @@ -332,7 +335,7 @@ object CheckUnused: * The optional name will be used to target the right import * as the same element can be imported with different renaming */ - def registerUsed(sym: Symbol, name: Option[Name])(using Context): Unit = + def registerUsed(sym: Symbol, name: Option[Name])(using Context): Unit = if !isConstructorOfSynth(sym) && !doNotRegister(sym) then if sym.isConstructor && sym.exists then registerUsed(sym.owner, None) // constructor are "implicitly" imported with the class @@ -368,7 +371,7 @@ object CheckUnused: implicitParamInScope += memDef else explicitParamInScope += memDef - else if currScopeType.top == ScopeType.Local then + else if currScopeType.top == ScopeType.Local then localDefInScope += memDef else if memDef.shouldReportPrivateDef then privateDefInScope += memDef diff --git a/tests/neg-custom-args/fatal-warnings/i15503i.scala b/tests/neg-custom-args/fatal-warnings/i15503i.scala index c4d95c7904fa..33e04f34daa8 100644 --- a/tests/neg-custom-args/fatal-warnings/i15503i.scala +++ b/tests/neg-custom-args/fatal-warnings/i15503i.scala @@ -75,6 +75,16 @@ package foo.test.companionprivate: private def b = c // OK def c = List(1,2,3) // OK +package foo.test.i16678: + def foo(func: Int => String, value: Int): String = func(value) // OK + + def run = + println(foo(number => number.toString, value = 5)) // OK + println(foo(number => "", value = 5)) // error + println(foo(func = number => "", value = 5)) // error + println(foo(func = number => number.toString, value = 5)) // OK + println(foo(func = _.toString, value = 5)) // OK + package foo.test.possibleclasses: case class AllCaseClass( k: Int, // OK @@ -120,4 +130,4 @@ package foo.test.from.i16675: case class PositiveNumber private (i: Int) // OK object PositiveNumber: def make(i: Int): Option[PositiveNumber] = //OK - Option.when(i >= 0)(PositiveNumber(i)) // OK \ No newline at end of file + Option.when(i >= 0)(PositiveNumber(i)) // OK