Skip to content

Commit b47f058

Browse files
som-snytttgodzik
authored andcommitted
Register expansion def for lint if in user code
[Cherry-picked 1eb4e79]
1 parent 176a4f0 commit b47f058

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
5858
if tree.symbol.exists then
5959
// if in an inline expansion, resolve at summonInline (synthetic pos) or in an enclosing call site
6060
val resolving =
61-
val inlineds = enclosingInlineds // per current context
62-
inlineds.isEmpty
61+
tree.srcPos.isUserCode
6362
|| tree.srcPos.isZeroExtentSynthetic // take as summonInline
64-
|| inlineds.last.srcPos.sourcePos.contains(tree.srcPos.sourcePos)
6563
if resolving && !ignoreTree(tree) then
6664
def loopOverPrefixes(prefix: Type, depth: Int): Unit =
6765
if depth < 10 && prefix.exists && !prefix.classSymbol.isEffectiveRoot then
@@ -465,7 +463,7 @@ object CheckUnused:
465463
val nowarn = mutable.Set.empty[Symbol] // marked @nowarn
466464
val imps = new IdentityHashMap[Import, Unit] // imports
467465
val sels = new IdentityHashMap[ImportSelector, Unit] // matched selectors
468-
def register(tree: Tree)(using Context): Unit = if enclosingInlineds.isEmpty then
466+
def register(tree: Tree)(using Context): Unit = if tree.srcPos.isUserCode then
469467
tree match
470468
case imp: Import =>
471469
if inliners == 0
@@ -1004,6 +1002,10 @@ object CheckUnused:
10041002
extension (pos: SrcPos)
10051003
def isZeroExtentSynthetic: Boolean = pos.span.isSynthetic && pos.span.isZeroExtent
10061004
def isSynthetic: Boolean = pos.span.isSynthetic && pos.span.exists
1005+
def isUserCode(using Context): Boolean =
1006+
val inlineds = enclosingInlineds // per current context
1007+
inlineds.isEmpty
1008+
|| inlineds.last.srcPos.sourcePos.contains(pos.sourcePos)
10071009

10081010
extension [A <: AnyRef](arr: Array[A])
10091011
// returns `until` if not satisfied

0 commit comments

Comments
 (0)