Skip to content

Commit

Permalink
Fix Exception in CheckUnused isOverriden() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
schuetzcarl committed Jun 19, 2023
1 parent 1f15b29 commit 175d4f3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class Compiler {
protected def frontendPhases: List[List[Phase]] =
List(new Parser) :: // Compiler frontend: scanner, parser
List(new TyperPhase) :: // Compiler frontend: namer, typer
List(new CheckUnused.PostTyper) :: // Check for unused elements
List(new CheckShadowing) :: // Check for shadowing elements
List(new CheckShadowing, new CheckUnused.PostTyper) :: // Check for unused elements // Check for shadowing elements
List(new YCheckPositions) :: // YCheck positions
List(new sbt.ExtractDependencies) :: // Sends information on classes' dependencies to sbt via callbacks
List(new semanticdb.ExtractSemanticDB) :: // Extract info into .semanticdb files
Expand Down
7 changes: 2 additions & 5 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ private sealed trait XSettings:
helpArg = "advanced warning",
descr = "Enable or disable specific `lint` warnings",
choices = List(
ChoiceWithHelp("nowarn", ""),
ChoiceWithHelp("all", ""),
ChoiceWithHelp("private-shadow", "Warn if a private field or class parameter shadows a superclass field"),
ChoiceWithHelp("type-parameter-shadow", "Warn when a type parameter shadows a type already in the scope"),
Expand All @@ -321,10 +320,8 @@ private sealed trait XSettings:
)

object XlintHas:
def isChoiceSet(s: String)(using Context) = Xlint.value.pipe(us => us.contains(s))
def allOr(s: String)(using Context) = Xlint.value.pipe(us => us.contains("all") || us.contains(s))
def nowarn(using Context) = allOr("nowarn")

def allOr(s: String)(using Context) =
Xlint.value.pipe(us => us.contains("all") || us.contains(s))
def privateShadow(using Context) =
allOr("private-shadow")
def typeParameterShadow(using Context) =
Expand Down
16 changes: 14 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,19 @@ object CheckUnused:
imp.expr.tpe.member(sel.name.toTypeName).alternatives.exists(_.symbol.isOneOf(GivenOrImplicit))
)

/** Returns some inherited symbol with the same type and name as the given "symDecl" */
private def lookForInheritedDecl(symDecl: Symbol)(using Context): Option[Symbol] =
val symDeclType = symDecl.info
val bClasses = symDecl.owner.info.baseClasses
bClasses match
case _ :: inherited =>
inherited
.map(classSymbol => symDecl.denot.matchingDecl(classSymbol, symDeclType))
.find(sym => sym.name == symDecl.name)
case Nil =>
None


extension (tree: ImportSelector)
def boundTpe: Type = tree.bound match {
case untpd.TypedSplice(tree1) => tree1.tpe
Expand Down Expand Up @@ -705,8 +718,7 @@ object CheckUnused:

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

end extension

Expand Down
4 changes: 2 additions & 2 deletions tests/neg-custom-args/fatal-warnings/i16639a.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ trait Bing
trait Accessors {
private var v1: Int = 0 // error warn
private var v2: Int = 0 // error warn, never set
private var v3: Int = 0 // warn, never got /Dotty: no warn even if not used
private var v3: Int = 0
private var v4: Int = 0 // no warn

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

def bippy(): Int = {
Expand Down

0 comments on commit 175d4f3

Please sign in to comment.