From 0d356254c4d6326398c9c1a587ad193fadef6883 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 6 Feb 2014 21:53:56 +0100 Subject: Catch stale references If a NamedType was denoted a SymDenotation one run, but stops being defined in the next, throw a staleSymbol error. --- src/dotty/tools/dotc/core/Denotations.scala | 5 ++++- src/dotty/tools/dotc/core/Types.scala | 8 ++++++-- src/dotty/tools/dotc/typer/Inferencing.scala | 4 ---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index e6d5023e5..90a6a373c 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -479,7 +479,7 @@ object Denotations { } while (d ne denot) initial.copyIfParentInvalid case _ => - throw new Error(s"stale symbol; $this, defined in run ${valid.runId} is referred to in run ${currentPeriod.runId}") + staleSymbolError } if (valid.runId != currentPeriod.runId) bringForward.current else { @@ -523,6 +523,9 @@ object Denotations { } } + def staleSymbolError(implicit ctx: Context) = + throw new Error(s"stale symbol; $this, defined in run ${myValidFor.runId} is referred to in run ${ctx.period.runId}") + /** For ClassDenotations only: * If caches influenced by parent classes are still valid, the denotation * itself, otherwise a freshly initialized copy. diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 2a6a5017f..28a7f9e67 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -1018,8 +1018,12 @@ object Types { case null => val sym = lastSymbol if (sym == null) loadDenot else denotOfSym(sym) - case d: SymDenotation if ctx.stillValid(d) => - d.current + case d: SymDenotation => + if (ctx.stillValid(d)) d.current + else { + val newd = loadDenot + if (newd.exists) newd else d.staleSymbolError + } case d => if (d.validFor.runId == ctx.period.runId) d.current else loadDenot diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala index a153f9066..868276598 100644 --- a/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/src/dotty/tools/dotc/typer/Inferencing.scala @@ -204,10 +204,6 @@ object Inferencing { */ abstract case class ViewProto(argType: Type, override val resultType: Type)(implicit ctx: Context) extends CachedGroundType with ApplyingProto { - // def lookingForInfo = resultType match { - // case rt: SelectionProto => rt.name.toString == "info" - // case _ => false - // } def isMatchedBy(tp: Type)(implicit ctx: Context): Boolean = /*ctx.conditionalTraceIndented(lookingForInfo, i"?.info isMatchedBy $tp ${tp.getClass}")*/ { ctx.typer.isApplicable(tp, argType :: Nil, resultType) } -- cgit v1.2.3