Skip to content

Commit 175d4f3

Browse files
committed
Fix Exception in CheckUnused isOverriden() helper
1 parent 1f15b29 commit 175d4f3

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
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
@@ -312,7 +312,6 @@ private sealed trait XSettings:
312312
helpArg = "advanced warning",
313313
descr = "Enable or disable specific `lint` warnings",
314314
choices = List(
315-
ChoiceWithHelp("nowarn", ""),
316315
ChoiceWithHelp("all", ""),
317316
ChoiceWithHelp("private-shadow", "Warn if a private field or class parameter shadows a superclass field"),
318317
ChoiceWithHelp("type-parameter-shadow", "Warn when a type parameter shadows a type already in the scope"),
@@ -321,10 +320,8 @@ private sealed trait XSettings:
321320
)
322321

323322
object XlintHas:
324-
def isChoiceSet(s: String)(using Context) = Xlint.value.pipe(us => us.contains(s))
325-
def allOr(s: String)(using Context) = Xlint.value.pipe(us => us.contains("all") || us.contains(s))
326-
def nowarn(using Context) = allOr("nowarn")
327-
323+
def allOr(s: String)(using Context) =
324+
Xlint.value.pipe(us => us.contains("all") || us.contains(s))
328325
def privateShadow(using Context) =
329326
allOr("private-shadow")
330327
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
@@ -633,6 +633,19 @@ object CheckUnused:
633633
imp.expr.tpe.member(sel.name.toTypeName).alternatives.exists(_.symbol.isOneOf(GivenOrImplicit))
634634
)
635635

636+
/** Returns some inherited symbol with the same type and name as the given "symDecl" */
637+
private def lookForInheritedDecl(symDecl: Symbol)(using Context): Option[Symbol] =
638+
val symDeclType = symDecl.info
639+
val bClasses = symDecl.owner.info.baseClasses
640+
bClasses match
641+
case _ :: inherited =>
642+
inherited
643+
.map(classSymbol => symDecl.denot.matchingDecl(classSymbol, symDeclType))
644+
.find(sym => sym.name == symDecl.name)
645+
case Nil =>
646+
None
647+
648+
636649
extension (tree: ImportSelector)
637650
def boundTpe: Type = tree.bound match {
638651
case untpd.TypedSplice(tree1) => tree1.tpe
@@ -705,8 +718,7 @@ object CheckUnused:
705718

706719
/** A function is overriden. Either has `override flags` or parent has a matching member (type and name) */
707720
private def isOverriden(using Context): Boolean =
708-
sym.is(Flags.Override) ||
709-
(sym.exists && sym.owner.thisType.parents.exists(p => sym.matchingMember(p).exists))
721+
sym.is(Flags.Override) || lookForInheritedDecl(sym).isDefined
710722

711723
end extension
712724

tests/neg-custom-args/fatal-warnings/i16639a.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ trait Bing
2626
trait Accessors {
2727
private var v1: Int = 0 // error warn
2828
private var v2: Int = 0 // error warn, never set
29-
private var v3: Int = 0 // warn, never got /Dotty: no warn even if not used
29+
private var v3: Int = 0
3030
private var v4: Int = 0 // no warn
3131

3232
private[this] var v5 = 0 // error warn, never set
33-
private[this] var v6 = 0 // warn, never got /Dotty: no warn even if not used
33+
private[this] var v6 = 0
3434
private[this] var v7 = 0 // no warn
3535

3636
def bippy(): Int = {

0 commit comments

Comments
 (0)