@@ -7,13 +7,13 @@ import dotty.tools.dotc.ast.untpd.ImportSelector
7
7
import dotty .tools .dotc .config .ScalaSettings
8
8
import dotty .tools .dotc .core .Contexts .*
9
9
import dotty .tools .dotc .core .Decorators .{em , i }
10
- import dotty .tools .dotc .core .Flags ._
10
+ import dotty .tools .dotc .core .Flags .*
11
11
import dotty .tools .dotc .core .Phases .Phase
12
12
import dotty .tools .dotc .core .StdNames
13
13
import dotty .tools .dotc .report
14
14
import dotty .tools .dotc .reporting .Message
15
15
import dotty .tools .dotc .typer .ImportInfo
16
- import dotty .tools .dotc .util .Property
16
+ import dotty .tools .dotc .util .{ Property , SrcPos }
17
17
import dotty .tools .dotc .core .Mode
18
18
import dotty .tools .dotc .core .Types .TypeTraverser
19
19
import dotty .tools .dotc .core .Types .Type
@@ -302,6 +302,7 @@ object CheckUnused:
302
302
* See the `isAccessibleAsIdent` extension method below in the file
303
303
*/
304
304
private val usedInScope = MutStack (MutSet [(Symbol ,Boolean , Option [Name ])]())
305
+ private val usedInPosition = MutSet [(SrcPos , Name )]()
305
306
/* unused import collected during traversal */
306
307
private val unusedImport = MutSet [ImportSelector ]()
307
308
@@ -351,6 +352,7 @@ object CheckUnused:
351
352
usedInScope.top += ((sym, sym.isAccessibleAsIdent, name))
352
353
usedInScope.top += ((sym.companionModule, sym.isAccessibleAsIdent, name))
353
354
usedInScope.top += ((sym.companionClass, sym.isAccessibleAsIdent, name))
355
+ name.map(n => usedInPosition += ((sym.sourcePos, n)))
354
356
355
357
/** Register a symbol that should be ignored */
356
358
def addIgnoredUsage (sym : Symbol )(using Context ): Unit =
@@ -455,6 +457,7 @@ object CheckUnused:
455
457
if ctx.settings.WunusedHas .locals then
456
458
localDefInScope
457
459
.filterNot(d => d.symbol.usedDefContains)
460
+ .filterNot(d => usedInPosition.exists { case (pos, name) => d.span.contains(pos.span) && name == d.symbol.name})
458
461
.map(d => d.namePos -> WarnTypes .LocalDefs ).toList
459
462
else
460
463
Nil
@@ -483,6 +486,7 @@ object CheckUnused:
483
486
if ctx.settings.WunusedHas .patvars then
484
487
patVarsInScope
485
488
.filterNot(d => d.symbol.usedDefContains)
489
+ .filterNot(d => usedInPosition.exists { case (pos, name) => d.span.contains(pos.span) && name == d.symbol.name})
486
490
.map(d => d.namePos -> WarnTypes .PatVars ).toList
487
491
else
488
492
Nil
0 commit comments