Skip to content

Commit bb55300

Browse files
schuetzcarlWojciechMazur
authored andcommitted
Separate CheckUnused and CheckShadowing into two MegaPhases
[Cherry-picked 0f4f7bf]
1 parent 26cc911 commit bb55300

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ 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 shadowing elements
3840
List(new YCheckPositions) :: // YCheck positions
3941
List(new sbt.ExtractDependencies) :: // Sends information on classes' dependencies to sbt via callbacks
4042
List(new semanticdb.ExtractSemanticDB) :: // Extract info into .semanticdb files
41-
List(new CheckUnused.PostTyper, new CheckShadowing) :: // Check for unused elements and shadowing elements
4243
List(new PostTyper) :: // Additional checks and cleanups after type checking
4344
List(new sjs.PrepJSInterop) :: // Additional checks and transformations for Scala.js (Scala.js only)
4445
List(new sbt.ExtractAPI) :: // Sends a representation of the API of classes to sbt via callbacks

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

+1-12
Original file line numberDiff line numberDiff line change
@@ -645,17 +645,6 @@ 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
659648

660649

661650
extension (tree: ImportSelector)
@@ -732,7 +721,7 @@ object CheckUnused:
732721

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

737726
end extension
738727

0 commit comments

Comments
 (0)