@@ -20,6 +20,7 @@ import dotty.tools.dotc.core.Types.{AnnotatedType, ConstantType, NoType, TermRef
20
20
import dotty .tools .dotc .core .Flags .flagsString
21
21
import dotty .tools .dotc .core .Flags
22
22
import dotty .tools .dotc .core .Names .Name
23
+ import dotty .tools .dotc .core .NameOps .isReplWrapperName
23
24
import dotty .tools .dotc .transform .MegaPhase .MiniPhase
24
25
import dotty .tools .dotc .core .Annotations
25
26
import dotty .tools .dotc .core .Definitions
@@ -423,9 +424,11 @@ object CheckUnused:
423
424
def registerImport (imp : tpd.Import )(using Context ): Unit =
424
425
if ! tpd.languageImport(imp.expr).nonEmpty && ! imp.isGeneratedByEnum && ! isTransparentAndInline(imp) then
425
426
impInScope.top += imp
426
- unusedImport ++= imp.selectors.filter { s =>
427
- ! shouldSelectorBeReported(imp, s) && ! isImportExclusion(s) && ! isImportIgnored(imp, s)
428
- }
427
+ if currScopeType.top != ScopeType .ReplWrapper then // #18383 Do not report top-level import's in the repl as unused
428
+ unusedImport ++= imp.selectors.filter { s =>
429
+ ! shouldSelectorBeReported(imp, s) && ! isImportExclusion(s) && ! isImportIgnored(imp, s)
430
+ }
431
+ end registerImport
429
432
430
433
/** Register (or not) some `val` or `def` according to the context, scope and flags */
431
434
def registerDef (memDef : tpd.MemberDef )(using Context ): Unit =
@@ -794,12 +797,13 @@ object CheckUnused:
794
797
enum ScopeType :
795
798
case Local
796
799
case Template
800
+ case ReplWrapper
797
801
case Other
798
802
799
803
object ScopeType :
800
804
/** return the scope corresponding to the enclosing scope of the given tree */
801
- def fromTree (tree : tpd.Tree ): ScopeType = tree match
802
- case _: tpd.Template => Template
805
+ def fromTree (tree : tpd.Tree )( using Context ) : ScopeType = tree match
806
+ case tree : tpd.Template => if tree.symbol.name.isReplWrapperName then ReplWrapper else Template
803
807
case _:tpd.Block => Local
804
808
case _ => Other
805
809
@@ -810,4 +814,3 @@ object CheckUnused:
810
814
val Empty = UnusedResult (Set .empty)
811
815
812
816
end CheckUnused
813
-
0 commit comments