Skip to content

Commit

Permalink
Add Phases#atInitialPhaseOf and use it where needed
Browse files Browse the repository at this point in the history
Using it in isDerivedValueClass fixes the bug showcased in scala#411.
  • Loading branch information
smarter committed Mar 18, 2015
1 parent 515d41f commit abc6950
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/dotty/tools/backend/jvm/DottyBackendInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,11 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
def originalOwner: Symbol = {
try {
if (sym.exists) {
val original = toDenot(sym).initial
val validity = original.validFor
val shiftedContext = ctx.withPhase(validity.phaseId)
val r = toDenot(sym)(shiftedContext).maybeOwner
if(r is Flags.Package) NoSymbol
else r
ctx.atInitialPhaseOf(toDenot(sym)) { implicit ctx =>
val r = toDenot(sym).maybeOwner
if (r is Flags.Package) NoSymbol
else r
}
} else NoSymbol
} catch {
case e: NotDefinedHere => NoSymbol // todo: do we have a method to tests this?
Expand Down
7 changes: 7 additions & 0 deletions src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ trait Phases {

def atNextPhase[T](op: Context => T): T = atPhase(phase.next)(op)

/** Execute `op` at the earliest phase were `ref` was valid */
def atInitialPhaseOf[T](ref: SingleDenotation)(op: Context => T): T = {
val original = ref.initial
val initialId = original.validFor.phaseId
atPhase(initialId)(op)
}

def atPhaseNotLaterThan[T](limit: Phase)(op: Context => T): T =
if (!limit.exists || phase <= limit) op(this) else atPhase(limit)(op)

Expand Down
4 changes: 3 additions & 1 deletion src/dotty/tools/dotc/transform/ValueClasses.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import StdNames._
object ValueClasses {

def isDerivedValueClass(d: SymDenotation)(implicit ctx: Context) =
d.isClass &&
ctx.atInitialPhaseOf(d) { implicit ctx =>
d.isClass &&
d.derivesFrom(defn.AnyValClass) &&
(d.symbol ne defn.AnyValClass) &&
!d.isPrimitiveValueClass
}

def isMethodWithExtension(d: SymDenotation)(implicit ctx: Context) =
d.isSourceMethod &&
Expand Down

0 comments on commit abc6950

Please sign in to comment.