Skip to content

Commit 685a4e1

Browse files
committed
Use enclosingInlineds
1 parent f7fd77d commit 685a4e1

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ 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-
refInfos.inlined.isEmpty
62-
|| tree.srcPos.isZeroExtentSynthetic
63-
|| refInfos.inlined.exists(_.sourcePos.contains(tree.srcPos.sourcePos))
61+
val inlineds = enclosingInlineds // per current context
62+
inlineds.isEmpty
63+
|| tree.srcPos.isZeroExtentSynthetic // take as summonInline
64+
|| inlineds.last.srcPos.sourcePos.contains(tree.srcPos.sourcePos)
6465
if resolving && !ignoreTree(tree) then
6566
def loopOverPrefixes(prefix: Type, depth: Int): Unit =
6667
if depth < 10 && prefix.exists && !prefix.classSymbol.isEffectiveRoot then
@@ -160,12 +161,8 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
160161
case _ =>
161162
tree
162163

163-
override def prepareForInlined(tree: Inlined)(using Context): Context =
164-
refInfos.inlined.push(tree.call.srcPos)
165-
ctx
166164
override def transformInlined(tree: Inlined)(using Context): tree.type =
167165
transformAllDeep(tree.call)
168-
val _ = refInfos.inlined.pop()
169166
tree
170167

171168
override def prepareForBind(tree: Bind)(using Context): Context =
@@ -500,7 +497,7 @@ object CheckUnused:
500497
val nowarn = mutable.Set.empty[Symbol] // marked @nowarn
501498
val imps = new IdentityHashMap[Import, Unit] // imports
502499
val sels = new IdentityHashMap[ImportSelector, Unit] // matched selectors
503-
def register(tree: Tree)(using Context): Unit = if inlined.isEmpty then
500+
def register(tree: Tree)(using Context): Unit = if enclosingInlineds.isEmpty then
504501
tree match
505502
case imp: Import =>
506503
if inliners == 0
@@ -529,7 +526,6 @@ object CheckUnused:
529526
if tree.symbol ne NoSymbol then
530527
defs.addOne((tree.symbol, tree.srcPos)) // TODO is this a code path
531528

532-
val inlined = Stack.empty[SrcPos] // enclosing call.srcPos of inlined code (expansions)
533529
var inliners = 0 // depth of inline def (not inlined yet)
534530

535531
// instead of refs.addOne, use addRef to distinguish a read from a write to var

0 commit comments

Comments
 (0)