diff --git a/src/dotty/tools/dotc/core/Phases.scala b/src/dotty/tools/dotc/core/Phases.scala index 4b2861452d0c..2a606f64ea4e 100644 --- a/src/dotty/tools/dotc/core/Phases.scala +++ b/src/dotty/tools/dotc/core/Phases.scala @@ -35,7 +35,12 @@ trait Phases { def atNextPhase[T](op: Context => T): T = atPhase(phase.next)(op) def atPhaseNotLaterThan[T](limit: Phase)(op: Context => T): T = - if (!limit.exists || phase <= limit) op(this) else atPhase(limit)(op) + if ((limit eq null) || !limit.exists || phase <= limit) op(this) else atPhase(limit)(op) + // limit can be null if we're initializing definitions and phase-caches return null + // or if phase is simply absent and all phases are "before". + + def atPhaseBefore[T](limit: Phase)(op: Context => T): T = + if ((limit eq null) || !limit.exists || phase < limit) op(this) else atPhase(limit.prev)(op) def atPhaseNotLaterThanTyper[T](op: Context => T): T = atPhaseNotLaterThan(base.typerPhase)(op) @@ -342,6 +347,9 @@ object Phases { final def <=(that: Phase) = exists && id <= that.id + final def <(that: Phase) = + exists && id <= that.id + final def prev: Phase = if (id > FirstPhaseId) myBase.phases(start - 1) else myBase.NoPhase diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 47ec541ab84c..6e3c424361cf 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -527,11 +527,18 @@ object SymDenotations { /** Is this denotation static (i.e. with no outer instance)? */ final def isStatic(implicit ctx: Context) = - (this is JavaStatic) || this.exists && owner.isStaticOwner || this.isRoot + ctx.addMode(Mode.FutureDefsOK).atPhaseBefore(ctx.lambdaLiftPhase) { implicit ctx => + (current.asSymDenotation is JavaStatic) || + this.exists && current.asSymDenotation.owner.isStaticOwner || + this.isRoot + } /** Is this a package class or module class that defines static symbols? */ final def isStaticOwner(implicit ctx: Context): Boolean = - (this is PackageClass) || (this is ModuleClass) && isStatic + ctx.addMode(Mode.FutureDefsOK).atPhaseBefore(ctx.lambdaLiftPhase) { implicit ctx => + (current.asSymDenotation is PackageClass) || + (current.asSymDenotation is ModuleClass) && current.asSymDenotation.isStatic + } /** Is this denotation defined in the same scope and compilation unit as that symbol? */ final def isCoDefinedWith(that: Symbol)(implicit ctx: Context) =