Skip to content

Commit 6424278

Browse files
szymon-rdKordyjan
authored andcommitted
Wunused: only filter out non-zero span-length givens
1 parent 0935386 commit 6424278

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
@@ -471,7 +471,7 @@ object CheckUnused:
471471
if ctx.settings.WunusedHas.implicits then
472472
implicitParamInScope
473473
.filterNot(d => d.symbol.usedDefContains)
474-
.filterNot(d => containsSyntheticSuffix(d.symbol) && !d.rawMods.is(Given))
474+
.filterNot(d => containsSyntheticSuffix(d.symbol) && (!d.rawMods.is(Given) || hasZeroLengthSpan(d.symbol)))
475475
.map(d => d.namePos -> WarnTypes.ImplicitParams).toList
476476
else
477477
Nil
@@ -512,11 +512,18 @@ object CheckUnused:
512512
val importedMembers = qual.tpe.member(sel.name).alternatives.map(_.symbol)
513513
importedMembers.exists(s => s.is(Transparent) && s.is(Inline))
514514
}).exists(identity)
515+
515516
/**
516517
* Heuristic to detect synthetic suffixes in names of symbols
517518
*/
518519
private def containsSyntheticSuffix(symbol: Symbol)(using Context): Boolean =
519520
symbol.name.mangledString.contains("$")
521+
522+
/**
523+
* Heuristic to detect generated symbols by checking if symbol has zero length span in source
524+
*/
525+
private def hasZeroLengthSpan(symbol: Symbol)(using Context): Boolean =
526+
symbol.span.end - symbol.span.start == 0
520527
/**
521528
* Is the the constructor of synthetic package object
522529
* Should be ignored as it is always imported/used in package

0 commit comments

Comments
 (0)