@@ -331,6 +331,8 @@ object CheckUnused:
331331 registerUsed(sym.owner, None ) // constructor are "implicitly" imported with the class
332332 else
333333 usedInScope.top += ((sym, sym.isAccessibleAsIdent, name))
334+ usedInScope.top += ((sym.companionModule, sym.isAccessibleAsIdent, name))
335+ usedInScope.top += ((sym.companionClass, sym.isAccessibleAsIdent, name))
334336
335337 /** Register a symbol that should be ignored */
336338 def addIgnoredUsage (sym : Symbol )(using Context ): Unit =
@@ -347,7 +349,7 @@ object CheckUnused:
347349
348350 /** Register an import */
349351 def registerImport (imp : tpd.Import )(using Context ): Unit =
350- if ! tpd.languageImport(imp.expr).nonEmpty then
352+ if ! tpd.languageImport(imp.expr).nonEmpty && ! imp.isGeneratedByEnum then
351353 impInScope.top += imp
352354 unusedImport ++= imp.selectors.filter { s =>
353355 ! shouldSelectorBeReported(imp, s) && ! isImportExclusion(s)
@@ -591,6 +593,10 @@ object CheckUnused:
591593 ! isSyntheticMainParam(sym) &&
592594 ! sym.shouldNotReportParamOwner
593595
596+ extension (imp : tpd.Import )
597+ /** Enum generate an import for its cases (but outside them), which should be ignored */
598+ def isGeneratedByEnum (using Context ): Boolean =
599+ imp.symbol.exists && imp.symbol.owner.is(Flags .Enum , butNot = Flags .Case )
594600
595601 extension (thisName : Name )
596602 private def isWildcard : Boolean =
0 commit comments