Skip to content

Commit d0d3711

Browse files
committed
Avoid taking import collection._ as exclusion
1 parent 0678aa3 commit d0d3711

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

compiler/src/dotty/tools/dotc/ast/untpd.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
139139
case Ident(rename: TermName) => rename
140140
case _ => name
141141

142-
def isUnimport = rename == nme.WILDCARD
142+
//def isUnimport = rename == nme.WILDCARD // && imported.name != nme.WILDCARD
143+
def isUnimport: Boolean = renamed match
144+
case Ident(nme.WILDCARD) => true
145+
case _ => false
143146
}
144147

145148
case class Number(digits: String, kind: NumberKind)(implicit @constructorOnly src: SourceFile) extends TermTree

compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

+8-10
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ import dotty.tools.dotc.util.Spans.Span
3636
import scala.math.Ordering
3737
import scala.util.chaining.given
3838

39-
/**
40-
* A compiler phase that checks for unused imports or definitions
39+
/** A compiler phase that checks for unused imports or definitions.
4140
*
42-
* Basically, it gathers definition/imports and their usage. If a
43-
* definition/imports does not have any usage, then it is reported.
41+
* Every construct that introduces a name must have at least one corresponding reference.
42+
* The analysis is restricted to definitions of limited scope, i.e., private and local definitions.
4443
*/
4544
class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _key: Property.Key[CheckUnused.UnusedData]) extends MiniPhase:
4645
import CheckUnused.*
@@ -726,7 +725,7 @@ object CheckUnused:
726725
sym.annotations.exists(a => a.symbol == ctx.definitions.UnusedAnnot)
727726

728727
private def shouldNotReportParamOwner(using Context): Boolean =
729-
if sym.exists then
728+
sym.exists && {
730729
val owner = sym.owner
731730
trivialDefs(owner) || // is a trivial def
732731
owner.isPrimaryConstructor ||
@@ -735,18 +734,17 @@ object CheckUnused:
735734
) ||
736735
owner.isAllOf(Synthetic | PrivateLocal) ||
737736
owner.is(Accessor) ||
738-
owner.isOverriden
739-
else
740-
false
737+
owner.isOverridden
738+
}
741739

742740
private def usedDefContains(using Context): Boolean =
743741
sym.everySymbol.exists(usedDef.apply)
744742

745743
private def everySymbol(using Context): List[Symbol] =
746744
List(sym, sym.companionClass, sym.companionModule, sym.moduleClass).filter(_.exists)
747745

748-
/** A function is overriden. Either has `override flags` or parent has a matching member (type and name) */
749-
private def isOverriden(using Context): Boolean =
746+
/** A function is overridden. Either has `override flags` or parent has a matching member (type and name) */
747+
private def isOverridden(using Context): Boolean =
750748
sym.is(Flags.Override) || (sym.exists && sym.owner.thisType.parents.exists(p => sym.matchingMember(p).exists))
751749

752750
end extension

0 commit comments

Comments
 (0)