Skip to content

Commit 4644e5e

Browse files
szymon-rdKordyjan
authored andcommitted
Wunused: only filter out non-zero span-length givens
1 parent 4070dbd commit 4644e5e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ object CheckUnused:
478478
if ctx.settings.WunusedHas.implicits then
479479
implicitParamInScope
480480
.filterNot(d => d.symbol.usedDefContains)
481-
.filterNot(d => containsSyntheticSuffix(d.symbol) && !d.rawMods.is(Given))
481+
.filterNot(d => containsSyntheticSuffix(d.symbol) && (!d.rawMods.is(Given) || hasZeroLengthSpan(d.symbol)))
482482
.map(d => d.namePos -> WarnTypes.ImplicitParams).toList
483483
else
484484
Nil
@@ -519,11 +519,18 @@ object CheckUnused:
519519
val importedMembers = qual.tpe.member(sel.name).alternatives.map(_.symbol)
520520
importedMembers.exists(s => s.is(Transparent) && s.is(Inline))
521521
}).exists(identity)
522+
522523
/**
523524
* Heuristic to detect synthetic suffixes in names of symbols
524525
*/
525526
private def containsSyntheticSuffix(symbol: Symbol)(using Context): Boolean =
526527
symbol.name.mangledString.contains("$")
528+
529+
/**
530+
* Heuristic to detect generated symbols by checking if symbol has zero length span in source
531+
*/
532+
private def hasZeroLengthSpan(symbol: Symbol)(using Context): Boolean =
533+
symbol.span.end - symbol.span.start == 0
527534
/**
528535
* Is the the constructor of synthetic package object
529536
* Should be ignored as it is always imported/used in package

0 commit comments

Comments
 (0)