Skip to content

Commit 9513ea0

Browse files
committed
Fix Exception in CheckUnused isOverriden() helper
[Cherry-picked 175d4f3][modified]
1 parent 6bf61a4 commit 9513ea0

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class Compiler {
3535
protected def frontendPhases: List[List[Phase]] =
3636
List(new Parser) :: // Compiler frontend: scanner, parser
3737
List(new TyperPhase) :: // Compiler frontend: namer, typer
38-
List(new CheckUnused.PostTyper) :: // Check for unused elements
39-
List(new CheckShadowing) :: // Check for shadowing elements
38+
List(new CheckShadowing, new CheckUnused.PostTyper) :: // Check for unused elements // Check for shadowing elements
4039
List(new YCheckPositions) :: // YCheck positions
4140
List(new sbt.ExtractDependencies) :: // Sends information on classes' dependencies to sbt via callbacks
4241
List(new semanticdb.ExtractSemanticDB) :: // Extract info into .semanticdb files

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ private sealed trait XSettings:
313313
helpArg = "advanced warning",
314314
descr = "Enable or disable specific `lint` warnings",
315315
choices = List(
316-
ChoiceWithHelp("nowarn", ""),
317316
ChoiceWithHelp("all", ""),
318317
ChoiceWithHelp("private-shadow", "Warn if a private field or class parameter shadows a superclass field"),
319318
ChoiceWithHelp("type-parameter-shadow", "Warn when a type parameter shadows a type already in the scope"),
@@ -322,10 +321,8 @@ private sealed trait XSettings:
322321
)
323322

324323
object XlintHas:
325-
def isChoiceSet(s: String)(using Context) = Xlint.value.pipe(us => us.contains(s))
326-
def allOr(s: String)(using Context) = Xlint.value.pipe(us => us.contains("all") || us.contains(s))
327-
def nowarn(using Context) = allOr("nowarn")
328-
324+
def allOr(s: String)(using Context) =
325+
Xlint.value.pipe(us => us.contains("all") || us.contains(s))
329326
def privateShadow(using Context) =
330327
allOr("private-shadow")
331328
def typeParameterShadow(using Context) =

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,19 @@ object CheckUnused:
645645
imp.expr.tpe.member(sel.name.toTypeName).alternatives.exists(_.symbol.isOneOf(GivenOrImplicit))
646646
)
647647

648+
/** Returns some inherited symbol with the same type and name as the given "symDecl" */
649+
private def lookForInheritedDecl(symDecl: Symbol)(using Context): Option[Symbol] =
650+
val symDeclType = symDecl.info
651+
val bClasses = symDecl.owner.info.baseClasses
652+
bClasses match
653+
case _ :: inherited =>
654+
inherited
655+
.map(classSymbol => symDecl.denot.matchingDecl(classSymbol, symDeclType))
656+
.find(sym => sym.name == symDecl.name)
657+
case Nil =>
658+
None
659+
660+
648661
extension (tree: ImportSelector)
649662
def boundTpe: Type = tree.bound match {
650663
case untpd.TypedSplice(tree1) => tree1.tpe
@@ -719,8 +732,7 @@ object CheckUnused:
719732

720733
/** A function is overriden. Either has `override flags` or parent has a matching member (type and name) */
721734
private def isOverriden(using Context): Boolean =
722-
sym.is(Flags.Override) ||
723-
(sym.exists && sym.owner.thisType.parents.exists(p => sym.matchingMember(p).exists))
735+
sym.is(Flags.Override) || lookForInheritedDecl(sym).isDefined
724736

725737
end extension
726738

0 commit comments

Comments
 (0)