From 8a2cbf411888083e810c765bf02242e224e31885 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 14 Dec 2014 15:08:08 +0100 Subject: Make sure the period of a context always contains a single phase Multi-phase periods mean that ctx.phaseId is no longer valid, which means a lot of invariants break. --- src/dotty/tools/dotc/core/Contexts.scala | 8 +++++--- src/dotty/tools/dotc/core/Phases.scala | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/dotty/tools/dotc/core') diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index 6824cc36c..805b7660c 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -77,7 +77,10 @@ object Contexts { /** The current context */ private[this] var _period: Period = _ - protected def period_=(period: Period) = _period = period + protected def period_=(period: Period) = { + assert(period.firstPhaseId == period.lastPhaseId, period) + _period = period + } def period: Period = _period /** The scope nesting level */ @@ -193,7 +196,7 @@ object Contexts { /** This context at given phase. * This method will always return a phase period equal to phaseId, thus will never return squashed phases */ - final def withPhase(phaseId: PhaseId): Context = { + final def withPhase(phaseId: PhaseId): Context = if (this.phaseId == phaseId) this else if (phasedCtx.phaseId == phaseId) phasedCtx else if (phasedCtxs != null && phasedCtxs(phaseId) != null) phasedCtxs(phaseId) @@ -206,7 +209,6 @@ object Contexts { } ctx1 } - } final def withPhase(phase: Phase): Context = withPhase(phase.id) diff --git a/src/dotty/tools/dotc/core/Phases.scala b/src/dotty/tools/dotc/core/Phases.scala index ffe2ddbea..c1bc243a0 100644 --- a/src/dotty/tools/dotc/core/Phases.scala +++ b/src/dotty/tools/dotc/core/Phases.scala @@ -194,7 +194,7 @@ object Phases { def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = units.map { unit => - val unitCtx = ctx.fresh.setPhase(this).setCompilationUnit(unit) + val unitCtx = ctx.fresh.setPhase(this.start).setCompilationUnit(unit) run(unitCtx) unitCtx.compilationUnit } -- cgit v1.2.3