Skip to content

Commit 176a4f0

Browse files
som-snytttgodzik
authored andcommitted
Use enclosingInlineds
[Cherry-picked 912e89b]
1 parent 6e29e59 commit 176a4f0

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 =
@@ -468,7 +465,7 @@ object CheckUnused:
468465
val nowarn = mutable.Set.empty[Symbol] // marked @nowarn
469466
val imps = new IdentityHashMap[Import, Unit] // imports
470467
val sels = new IdentityHashMap[ImportSelector, Unit] // matched selectors
471-
def register(tree: Tree)(using Context): Unit = if inlined.isEmpty then
468+
def register(tree: Tree)(using Context): Unit = if enclosingInlineds.isEmpty then
472469
tree match
473470
case imp: Import =>
474471
if inliners == 0
@@ -497,7 +494,6 @@ object CheckUnused:
497494
if tree.symbol ne NoSymbol then
498495
defs.addOne((tree.symbol, tree.srcPos)) // TODO is this a code path
499496

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

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

0 commit comments

Comments
 (0)