Skip to content

Commit 6195663

Browse files
committed
WIP: Disable WUnused for params of non-private defs
1 parent bcaa1ca commit 6195663

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
@@ -114,6 +114,10 @@ class CheckUnused extends MiniPhase:
114114

115115
override def prepareForDefDef(tree: tpd.DefDef)(using Context): Context =
116116
unusedDataApply{ ud =>
117+
if !tree.rawMods.is(Private) then
118+
tree.termParamss.flatten.foreach { p =>
119+
ud.addIgnoredParam(p.symbol)
120+
}
117121
import ud.registerTrivial
118122
tree.registerTrivial
119123
traverseAnnotations(tree.symbol)
@@ -331,6 +335,8 @@ object CheckUnused:
331335
/** Trivial definitions, avoid registering params */
332336
private val trivialDefs = MutSet[Symbol]()
333337

338+
private val paramsToSkip = MutSet[Symbol]()
339+
334340
/**
335341
* Push a new Scope of the given type, executes the given Unit and
336342
* pop it back to the original type.
@@ -365,6 +371,10 @@ object CheckUnused:
365371
def removeIgnoredUsage(sym: Symbol)(using Context): Unit =
366372
doNotRegister --= sym.everySymbol
367373

374+
def addIgnoredParam(sym: Symbol)(using Context): Unit =
375+
paramsToSkip += sym
376+
377+
368378

369379
/** Register an import */
370380
def registerImport(imp: tpd.Import)(using Context): Unit =
@@ -380,7 +390,7 @@ object CheckUnused:
380390
if memDef.isValidParam then
381391
if memDef.symbol.isOneOf(GivenOrImplicit) then
382392
implicitParamInScope += memDef
383-
else
393+
else if !paramsToSkip.contains(memDef.symbol) then
384394
explicitParamInScope += memDef
385395
else if currScopeType.top == ScopeType.Local then
386396
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)