Skip to content

Commit 8a2cbf4

Browse files
committed
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.
1 parent e7a4197 commit 8a2cbf4

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ object Contexts {
7777

7878
/** The current context */
7979
private[this] var _period: Period = _
80-
protected def period_=(period: Period) = _period = period
80+
protected def period_=(period: Period) = {
81+
assert(period.firstPhaseId == period.lastPhaseId, period)
82+
_period = period
83+
}
8184
def period: Period = _period
8285

8386
/** The scope nesting level */
@@ -193,7 +196,7 @@ object Contexts {
193196
/** This context at given phase.
194197
* This method will always return a phase period equal to phaseId, thus will never return squashed phases
195198
*/
196-
final def withPhase(phaseId: PhaseId): Context = {
199+
final def withPhase(phaseId: PhaseId): Context =
197200
if (this.phaseId == phaseId) this
198201
else if (phasedCtx.phaseId == phaseId) phasedCtx
199202
else if (phasedCtxs != null && phasedCtxs(phaseId) != null) phasedCtxs(phaseId)
@@ -206,7 +209,6 @@ object Contexts {
206209
}
207210
ctx1
208211
}
209-
}
210212

211213
final def withPhase(phase: Phase): Context =
212214
withPhase(phase.id)

src/dotty/tools/dotc/core/Phases.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ object Phases {
194194

195195
def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] =
196196
units.map { unit =>
197-
val unitCtx = ctx.fresh.setPhase(this).setCompilationUnit(unit)
197+
val unitCtx = ctx.fresh.setPhase(this.start).setCompilationUnit(unit)
198198
run(unitCtx)
199199
unitCtx.compilationUnit
200200
}

0 commit comments

Comments
 (0)