@@ -10,7 +10,7 @@ import dotty.tools.dotc.core.Decorators.{em, i}
1010import dotty .tools .dotc .core .Flags .*
1111import dotty .tools .dotc .core .Phases .Phase
1212import dotty .tools .dotc .core .StdNames
13- import dotty .tools .dotc .{ ast , report }
13+ import dotty .tools .dotc .report
1414import dotty .tools .dotc .reporting .Message
1515import dotty .tools .dotc .typer .ImportInfo
1616import dotty .tools .dotc .util .{Property , SrcPos }
@@ -368,7 +368,7 @@ object CheckUnused:
368368
369369 /** Register an import */
370370 def registerImport (imp : tpd.Import )(using Context ): Unit =
371- if ! tpd.languageImport(imp.expr).nonEmpty && ! imp.isGeneratedByEnum then
371+ if ! tpd.languageImport(imp.expr).nonEmpty && ! imp.isGeneratedByEnum && ! isTransparentAndInline(imp) then
372372 impInScope.top += imp
373373 unusedImport ++= imp.selectors.filter { s =>
374374 ! shouldSelectorBeReported(imp, s) && ! isImportExclusion(s)
@@ -433,19 +433,6 @@ object CheckUnused:
433433 exists
434434 }
435435
436- // not report unused transparent inline imports
437- for {
438- imp <- imports
439- sel <- imp.selectors
440- } {
441- if unusedImport.contains(sel) then
442- val tpd .Import (qual, _) = imp
443- val importedMembers = qual.tpe.member(sel.name).alternatives.map(_.symbol)
444- val isTransparentAndInline = importedMembers.exists(s => s.is(Transparent ) && s.is(Inline ))
445- if isTransparentAndInline then
446- unusedImport -= sel
447- }
448-
449436 // if there's an outer scope
450437 if usedInScope.nonEmpty then
451438 // we keep the symbols not referencing an import in this scope
@@ -520,6 +507,18 @@ object CheckUnused:
520507 end getUnused
521508 // ============================ HELPERS ====================================
522509
510+
511+ /**
512+ * Checks if import selects a def that is transparent and inline
513+ */
514+ private def isTransparentAndInline (imp : tpd.Import )(using Context ): Boolean =
515+ (for {
516+ sel <- imp.selectors
517+ } yield {
518+ val qual = imp.expr
519+ val importedMembers = qual.tpe.member(sel.name).alternatives.map(_.symbol)
520+ importedMembers.exists(s => s.is(Transparent ) && s.is(Inline ))
521+ }).exists(identity)
523522 /**
524523 * Heuristic to detect synthetic suffixes in names of symbols
525524 */
0 commit comments