From abc6950f4edba9fd1ce6784171144cdd66c00caf Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Wed, 18 Mar 2015 19:06:00 +0100 Subject: [PATCH] Add Phases#atInitialPhaseOf and use it where needed Using it in isDerivedValueClass fixes the bug showcased in #411. --- .../tools/backend/jvm/DottyBackendInterface.scala | 11 +++++------ src/dotty/tools/dotc/core/Phases.scala | 7 +++++++ src/dotty/tools/dotc/transform/ValueClasses.scala | 4 +++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index 111a5f5f518a..fe1c7104b563 100644 --- a/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -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? diff --git a/src/dotty/tools/dotc/core/Phases.scala b/src/dotty/tools/dotc/core/Phases.scala index bf2b34f3c903..ea36546f0fda 100644 --- a/src/dotty/tools/dotc/core/Phases.scala +++ b/src/dotty/tools/dotc/core/Phases.scala @@ -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) diff --git a/src/dotty/tools/dotc/transform/ValueClasses.scala b/src/dotty/tools/dotc/transform/ValueClasses.scala index c2239e3f69c3..43e6ff1468f6 100644 --- a/src/dotty/tools/dotc/transform/ValueClasses.scala +++ b/src/dotty/tools/dotc/transform/ValueClasses.scala @@ -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 &&