From 502f426981105df448896f635ef559cd72787c43 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 16 Aug 2013 19:01:08 +0200 Subject: Various bugfixes for namer/typer/trees --- src/dotty/tools/dotc/core/Denotations.scala | 6 ++++-- src/dotty/tools/dotc/core/Periods.scala | 6 +++--- src/dotty/tools/dotc/core/SymDenotations.scala | 18 +++++++++++++----- src/dotty/tools/dotc/core/Symbols.scala | 4 ++++ src/dotty/tools/dotc/core/Types.scala | 4 ++++ src/dotty/tools/dotc/core/transform/Erasure.scala | 6 +++++- 6 files changed, 33 insertions(+), 11 deletions(-) (limited to 'src/dotty/tools/dotc/core') diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index e551c8af2..4566cfdb8 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -456,7 +456,9 @@ object Denotations { val valid = myValidFor def stillValid(denot: SymDenotation): Boolean = if (!denot.exists || (denot.flags is PackageClass)) true - else if (denot.owner is PackageClass) denot.owner.decls.lookup(denot.name) eq symbol + else if (denot.owner is PackageClass) + (denot.owner.decls.lookup(denot.name) eq denot.symbol) || + (denot is ModuleClass) && stillValid(denot.sourceModule) // !!! DEBUG - we should check why module classes are not entered else stillValid(denot.owner) def bringForward(): SingleDenotation = this match { case denot: SymDenotation if stillValid(denot) => @@ -467,7 +469,7 @@ object Denotations { } while (d ne denot) initial.copyIfParentInvalid case _ => - throw new Error(s"stale symbol; ${symbol.showLocated}, defined in run ${valid.runId} is referred to in run ${currentPeriod.runId}") + throw new Error(s"stale symbol; $this, defined in run ${valid.runId} is referred to in run ${currentPeriod.runId}") } if (valid.runId != currentPeriod.runId) bringForward.current else { diff --git a/src/dotty/tools/dotc/core/Periods.scala b/src/dotty/tools/dotc/core/Periods.scala index 55a485201..8a1b65f2c 100644 --- a/src/dotty/tools/dotc/core/Periods.scala +++ b/src/dotty/tools/dotc/core/Periods.scala @@ -56,13 +56,13 @@ object Periods { class Period(val code: Int) extends AnyVal { /** The run identifier of this period. */ - def runId: Int = code >>> (PhaseWidth * 2) + def runId: RunId = code >>> (PhaseWidth * 2) /** The phase identifier of this single-phase period. */ - def phaseId: Int = (code >>> PhaseWidth) & PhaseMask + def phaseId: PhaseId = (code >>> PhaseWidth) & PhaseMask /** The last phase of this period */ - def lastPhaseId: Int = + def lastPhaseId: PhaseId = (code >>> PhaseWidth) & PhaseMask /** The first phase of this period */ diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index d2b2a6fe4..910fec909 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -437,11 +437,15 @@ object SymDenotations { * the completers. */ /** The class implementing this module, NoSymbol if not applicable. */ - final def moduleClass: Symbol = myInfo match { - case info: TypeRefBySym if this is ModuleVal => info.fixedSym - case info: ModuleCompleter => info.mclass - case _ => NoSymbol - } + final def moduleClass: Symbol = + if (this is ModuleVal) + myInfo match { + case info: TypeRefBySym => info.fixedSym + case ExprType(info: TypeRefBySym) => info.fixedSym // needed after uncurry, when module terms might be accessor defs + case info: ModuleCompleter => info.mclass + case _ => NoSymbol + } + else NoSymbol /** The module implemented by this module class, NoSymbol if not applicable. */ final def sourceModule: Symbol = myInfo match { @@ -841,6 +845,10 @@ object SymDenotations { case scope: MutableScope => scope case _ => decls.asInstanceOf[MutableScope] } + if (this is PackageClass) { // replace existing symbols + val entry = mscope.lookupEntry(sym.name) + if (entry != null) mscope.unlink(entry) + } mscope.enter(sym) if (myMemberFingerPrint != FingerPrint.unknown) diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala index 1e3fe4e52..3e8b13320 100644 --- a/src/dotty/tools/dotc/core/Symbols.scala +++ b/src/dotty/tools/dotc/core/Symbols.scala @@ -320,6 +320,10 @@ object Symbols { denot } + /** The run-id when this symbol was last defined */ + final def defRunId: RunId = + if (lastDenot == null) NoRunId else lastDenot.validFor.runId + /** Subclass tests and casts */ final def isTerm(implicit ctx: Context): Boolean = denot.isTerm final def isType(implicit ctx: Context): Boolean = denot.isType diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 49ad67c49..cf756859f 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -330,6 +330,8 @@ object Types { tp.decls.denotsNamed(name).filterExcluded(excluded).toDenot(NoPrefix) case tp: TypeProxy => tp.underlying.findDecl(name, excluded) + case ErrorType => + ctx.newErrorSymbol(classSymbol orElse defn.RootClass, name) } /** The member of this type with the given name */ @@ -756,6 +758,8 @@ object Types { tp.underlying.appliedTo(args) case AndType(l, r) => l.appliedTo(args) & r + case ErrorType => + this } } diff --git a/src/dotty/tools/dotc/core/transform/Erasure.scala b/src/dotty/tools/dotc/core/transform/Erasure.scala index 5b8a492e1..31679f05e 100644 --- a/src/dotty/tools/dotc/core/transform/Erasure.scala +++ b/src/dotty/tools/dotc/core/transform/Erasure.scala @@ -2,7 +2,7 @@ package dotty.tools.dotc package core package transform -import Symbols._, Types._, Contexts._, Flags._, Names._ +import Symbols._, Types._, Contexts._, Flags._, Names._, StdNames._ object Erasure { @@ -63,6 +63,8 @@ object Erasure { else if (cls == defn.ArrayClass) defn.ObjectClass.typeConstructor :: Nil else removeLaterObjects(classParents mapConserve (erasure(_).asInstanceOf[TypeRef])) tp.derivedClassInfo(erasure(pre), parents, NoType) + case ErrorType => + tp } def eraseArray(tp: RefinedType)(implicit ctx: Context) = { @@ -124,6 +126,8 @@ object Erasure { paramSignature(tp1) case OrType(tp1, tp2) => lubClass(tp1, tp2).name + case ErrorType => + tpnme.WILDCARD } def resultErasure(tp: Type)(implicit ctx: Context) = -- cgit v1.2.3