Skip to content

Commit 03dba67

Browse files
szymon-rdKordyjan
authored andcommitted
WIP: Disable WUnused for params of non-private defs
1 parent e369d90 commit 03dba67

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
118118

119119
override def prepareForDefDef(tree: tpd.DefDef)(using Context): Context =
120120
unusedDataApply{ ud =>
121+
if !tree.rawMods.is(Private) then
122+
tree.termParamss.flatten.foreach { p =>
123+
ud.addIgnoredParam(p.symbol)
124+
}
121125
import ud.registerTrivial
122126
tree.registerTrivial
123127
traverseAnnotations(tree.symbol)
@@ -350,6 +354,8 @@ object CheckUnused:
350354
/** Trivial definitions, avoid registering params */
351355
private val trivialDefs = MutSet[Symbol]()
352356

357+
private val paramsToSkip = MutSet[Symbol]()
358+
353359
/**
354360
* Push a new Scope of the given type, executes the given Unit and
355361
* pop it back to the original type.
@@ -396,6 +402,10 @@ object CheckUnused:
396402
def removeIgnoredUsage(sym: Symbol)(using Context): Unit =
397403
doNotRegister --= sym.everySymbol
398404

405+
def addIgnoredParam(sym: Symbol)(using Context): Unit =
406+
paramsToSkip += sym
407+
408+
399409

400410
/** Register an import */
401411
def registerImport(imp: tpd.Import)(using Context): Unit =
@@ -411,7 +421,7 @@ object CheckUnused:
411421
if memDef.isValidParam then
412422
if memDef.symbol.isOneOf(GivenOrImplicit) then
413423
implicitParamInScope += memDef
414-
else
424+
else if !paramsToSkip.contains(memDef.symbol) then
415425
explicitParamInScope += memDef
416426
else if currScopeType.top == ScopeType.Local then
417427
localDefInScope += memDef

tests/neg-custom-args/fatal-warnings/i15503-scala2/scala2-t11681.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait InterFace {
99
}
1010

1111
trait BadAPI extends InterFace {
12-
def f(a: Int,
12+
private def f(a: Int,
1313
b: String, // error
1414
c: Double): Int = {
1515
println(c)

0 commit comments

Comments
 (0)