@@ -101,8 +101,16 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
101
101
popScope(tree)
102
102
tree
103
103
104
+ // Megaphase will feed us Inlined(call, bindings, expansion) bindings and expansion,
105
+ // but we care about call only.
106
+ override def prepareForInlined (tree : Inlined )(using Context ): Context =
107
+ preparing :
108
+ ud.exclude.top.addAll(tree.bindings)
109
+ ud.exclude.top.addOne(tree.expansion)
110
+
104
111
override def transformInlined (tree : Inlined )(using Context ): tree.type =
105
- transformAllDeep(tree.call)
112
+ if phaseMode == PhaseMode .Aggregate then
113
+ transformAllDeep(tree.call)
106
114
tree
107
115
108
116
override def transformTypeTree (tree : TypeTree )(using Context ): tree.type =
@@ -343,6 +351,8 @@ object CheckUnused:
343
351
344
352
private val paramsToSkip = mut.Set .empty[Symbol ]
345
353
354
+ val exclude = Stack (ListBuffer .empty[Tree ])
355
+
346
356
def finishAggregation (using Context )(): Unit =
347
357
unusedAggregate = unusedAggregate match
348
358
case None =>
@@ -360,7 +370,9 @@ object CheckUnused:
360
370
* as the same element can be imported with different renaming.
361
371
*/
362
372
def registerUsed (sym : Symbol , name : Option [Name ], prefix : Type = NoPrefix , includeForImport : Boolean = true , tree : Tree )(using Context ): Unit =
363
- if sym.exists && ! isConstructorOfSynth(sym) && ! doNotRegister(sym) && ! doNotRegisterPrefix(prefix.typeSymbol) then
373
+ if sym.exists && ! isConstructorOfSynth(sym) && ! doNotRegister(sym) && ! doNotRegisterPrefix(prefix.typeSymbol)
374
+ && ! exclude.top.exists(_ eq tree)
375
+ then
364
376
if sym.isConstructor then
365
377
// constructors are "implicitly" imported with the class
366
378
registerUsed(sym.owner, name = None , prefix, includeForImport = includeForImport, tree = tree)
@@ -447,6 +459,7 @@ object CheckUnused:
447
459
impInScope.push(ListBuffer .empty)
448
460
usedInScope.push(mut.Map .empty)
449
461
this .parents.push(parents)
462
+ exclude.push(ListBuffer .empty)
450
463
451
464
def registerSetVar (sym : Symbol ): Unit =
452
465
setVars += sym
@@ -475,6 +488,7 @@ object CheckUnused:
475
488
unusedImport += selData
476
489
477
490
this .parents.pop()
491
+ exclude.pop()
478
492
end popScope
479
493
480
494
/** Leave the scope and return a result set of warnings.
@@ -594,9 +608,10 @@ object CheckUnused:
594
608
||
595
609
imp.expr.tpe.member(sel.name.toTermName).alternatives.exists(p => derivesFromCanEqual(p.symbol))
596
610
597
- /** Ignore definitions of CanEqual given.
611
+ /** Ignore definitions of CanEqual given, and ignore certain other trees .
598
612
*/
599
- private def isDefIgnored (memDef : MemberDef )(using Context ): Boolean = derivesFromCanEqual(memDef.symbol)
613
+ private def isDefIgnored (tree : Tree )(using Context ): Boolean =
614
+ exclude.top.exists(t => t.find(_ eq tree).isDefined) || derivesFromCanEqual(tree.symbol)
600
615
601
616
extension (sel : ImportSelector )
602
617
def boundTpe : Type = sel.bound match
0 commit comments