Skip to content

Commit

Permalink
Separate CheckUnused and CheckShadowing into two MegaPhases
Browse files Browse the repository at this point in the history
[Cherry-picked 0f4f7bf]
  • Loading branch information
schuetzcarl authored and WojciechMazur committed Jun 19, 2024
1 parent 26cc911 commit bb55300
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ 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 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
List(new CheckUnused.PostTyper, new CheckShadowing) :: // Check for unused elements and shadowing elements
List(new PostTyper) :: // Additional checks and cleanups after type checking
List(new sjs.PrepJSInterop) :: // Additional checks and transformations for Scala.js (Scala.js only)
List(new sbt.ExtractAPI) :: // Sends a representation of the API of classes to sbt via callbacks
Expand Down
13 changes: 1 addition & 12 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -645,17 +645,6 @@ 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)
Expand Down Expand Up @@ -732,7 +721,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) || lookForInheritedDecl(sym).isDefined
sym.is(Flags.Override) || (sym.exists && sym.owner.thisType.parents.exists(p => sym.matchingMember(p).exists))

end extension

Expand Down

0 comments on commit bb55300

Please # to comment.