diff --git a/compiler/src/dotty/tools/dotc/Compiler.scala b/compiler/src/dotty/tools/dotc/Compiler.scala index 5444bc3f41b6..6727fc4e91c0 100644 --- a/compiler/src/dotty/tools/dotc/Compiler.scala +++ b/compiler/src/dotty/tools/dotc/Compiler.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index c144364f68ba..0922ed0d2d22 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -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"), @@ -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) = diff --git a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala index bd521c8679d0..572734ccd809 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala @@ -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 @@ -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 diff --git a/tests/neg-custom-args/fatal-warnings/i16639a.scala b/tests/neg-custom-args/fatal-warnings/i16639a.scala index c62910b7f566..89f8bfef1b17 100644 --- a/tests/neg-custom-args/fatal-warnings/i16639a.scala +++ b/tests/neg-custom-args/fatal-warnings/i16639a.scala @@ -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 = {