Skip to content

Fix SymDenot.isStatic & isStaticOwner after lambdaLift. #1475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
11 changes: 9 additions & 2 deletions src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down