Skip to content

Commit a536a1b

Browse files
committed
Register expansion def for lint if in user code
1 parent 685a4e1 commit a536a1b

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
@@ -497,7 +495,7 @@ object CheckUnused:
497495
val nowarn = mutable.Set.empty[Symbol] // marked @nowarn
498496
val imps = new IdentityHashMap[Import, Unit] // imports
499497
val sels = new IdentityHashMap[ImportSelector, Unit] // matched selectors
500-
def register(tree: Tree)(using Context): Unit = if enclosingInlineds.isEmpty then
498+
def register(tree: Tree)(using Context): Unit = if tree.srcPos.isUserCode then
501499
tree match
502500
case imp: Import =>
503501
if inliners == 0
@@ -1036,6 +1034,10 @@ object CheckUnused:
10361034
extension (pos: SrcPos)
10371035
def isZeroExtentSynthetic: Boolean = pos.span.isSynthetic && pos.span.isZeroExtent
10381036
def isSynthetic: Boolean = pos.span.isSynthetic && pos.span.exists
1037+
def isUserCode(using Context): Boolean =
1038+
val inlineds = enclosingInlineds // per current context
1039+
inlineds.isEmpty
1040+
|| inlineds.last.srcPos.sourcePos.contains(pos.sourcePos)
10391041

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

0 commit comments

Comments
 (0)