@@ -101,8 +101,16 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
101101 popScope(tree)
102102 tree
103103
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+
104111 override def transformInlined (tree : Inlined )(using Context ): tree.type =
105- transformAllDeep(tree.call)
112+ if phaseMode == PhaseMode .Aggregate then
113+ transformAllDeep(tree.call)
106114 tree
107115
108116 override def transformTypeTree (tree : TypeTree )(using Context ): tree.type =
@@ -343,6 +351,8 @@ object CheckUnused:
343351
344352 private val paramsToSkip = mut.Set .empty[Symbol ]
345353
354+ val exclude = Stack (ListBuffer .empty[Tree ])
355+
346356 def finishAggregation (using Context )(): Unit =
347357 unusedAggregate = unusedAggregate match
348358 case None =>
@@ -360,7 +370,9 @@ object CheckUnused:
360370 * as the same element can be imported with different renaming.
361371 */
362372 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
364376 if sym.isConstructor then
365377 // constructors are "implicitly" imported with the class
366378 registerUsed(sym.owner, name = None , prefix, includeForImport = includeForImport, tree = tree)
@@ -447,6 +459,7 @@ object CheckUnused:
447459 impInScope.push(ListBuffer .empty)
448460 usedInScope.push(mut.Map .empty)
449461 this .parents.push(parents)
462+ exclude.push(ListBuffer .empty)
450463
451464 def registerSetVar (sym : Symbol ): Unit =
452465 setVars += sym
@@ -475,6 +488,7 @@ object CheckUnused:
475488 unusedImport += selData
476489
477490 this .parents.pop()
491+ exclude.pop()
478492 end popScope
479493
480494 /** Leave the scope and return a result set of warnings.
@@ -594,9 +608,10 @@ object CheckUnused:
594608 ||
595609 imp.expr.tpe.member(sel.name.toTermName).alternatives.exists(p => derivesFromCanEqual(p.symbol))
596610
597- /** Ignore definitions of CanEqual given.
611+ /** Ignore definitions of CanEqual given, and ignore certain other trees .
598612 */
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)
600615
601616 extension (sel : ImportSelector )
602617 def boundTpe : Type = sel.bound match
0 commit comments