Skip to content

Commit 75358be

Browse files
committed
Fix select static
Need to do time travel to find out whether members were created as static symbols. After LambdaLift and Flatten most symbols are static anyway.
1 parent 07ea487 commit 75358be

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ trait SymDenotations { this: Context =>
4646
val initial = denot.initial
4747
val firstPhaseId = initial.validFor.firstPhaseId.max(ctx.typerPhase.id)
4848
if ((initial ne denot) || ctx.phaseId != firstPhaseId)
49-
ctx.withPhase(firstPhaseId).stillValidInOwner(initial.asSymDenotation)
49+
ctx.withPhase(firstPhaseId).stillValidInOwner(initial)
5050
else
5151
stillValidInOwner(denot)
5252
}
@@ -77,7 +77,7 @@ trait SymDenotations { this: Context =>
7777
implicit val ctx: Context = this
7878
val initial = denot.initial
7979
if ((initial ne denot) || ctx.phaseId != initial.validFor.firstPhaseId) {
80-
ctx.withPhase(initial.validFor.firstPhaseId).traceInvalid(initial.asSymDenotation)
80+
ctx.withPhase(initial.validFor.firstPhaseId).traceInvalid(initial)
8181
} else try {
8282
val owner = denot.owner.denot
8383
if (!traceInvalid(owner)) explainSym("owner is invalid")
@@ -346,14 +346,14 @@ object SymDenotations {
346346
else {
347347
def legalize(name: Name): Name = // JVM method names may not contain `<' or `>' characters
348348
if (is(Method)) name.replace('<', '(').replace('>', ')') else name
349-
legalize(name.expandedName(initial.asSymDenotation.owner))
349+
legalize(name.expandedName(initial.owner))
350350
}
351351
// need to use initial owner to disambiguate, as multiple private symbols with the same name
352352
// might have been moved from different origins into the same class
353353

354354
/** The name with which the denoting symbol was created */
355355
final def originalName(implicit ctx: Context) = {
356-
val d = initial.asSymDenotation
356+
val d = initial
357357
if (d is ExpandedName) d.name.unexpandedName else d.name // !!!DEBUG, was: effectiveName
358358
}
359359

@@ -435,13 +435,13 @@ object SymDenotations {
435435

436436
/** Is this symbol an anonymous class? */
437437
final def isAnonymousClass(implicit ctx: Context): Boolean =
438-
isClass && (initial.asSymDenotation.name startsWith tpnme.ANON_CLASS)
438+
isClass && (initial.name startsWith tpnme.ANON_CLASS)
439439

440440
final def isAnonymousFunction(implicit ctx: Context) =
441-
this.symbol.is(Method) && (initial.asSymDenotation.name startsWith nme.ANON_FUN)
441+
this.symbol.is(Method) && (initial.name startsWith nme.ANON_FUN)
442442

443443
final def isAnonymousModuleVal(implicit ctx: Context) =
444-
this.symbol.is(ModuleVal) && (initial.asSymDenotation.name startsWith nme.ANON_CLASS)
444+
this.symbol.is(ModuleVal) && (initial.name startsWith nme.ANON_CLASS)
445445

446446
/** Is this a companion class method or companion object method?
447447
* These methods are generated by Symbols#synthesizeCompanionMethod
@@ -606,7 +606,7 @@ object SymDenotations {
606606

607607
/** Is this symbol a class that extends `AnyVal`? */
608608
final def isValueClass(implicit ctx: Context): Boolean = {
609-
val di = this.initial.asSymDenotation
609+
val di = initial
610610
di.isClass &&
611611
di.derivesFrom(defn.AnyValClass)(ctx.withPhase(di.validFor.firstPhaseId))
612612
// We call derivesFrom at the initial phase both because AnyVal does not exist
@@ -1164,6 +1164,8 @@ object SymDenotations {
11641164
d
11651165
}
11661166

1167+
override def initial: SymDenotation = super.initial.asSymDenotation
1168+
11671169
/** Install this denotation as the result of the given denotation transformer. */
11681170
override def installAfter(phase: DenotTransformer)(implicit ctx: Context): Unit =
11691171
super.installAfter(phase)
@@ -1226,10 +1228,13 @@ object SymDenotations {
12261228
if (myTypeParams == null)
12271229
myTypeParams =
12281230
if (ctx.erasedTypes || is(Module)) Nil // fast return for modules to avoid scanning package decls
1229-
else if (this ne initial) initial.asSymDenotation.typeParams
1230-
else infoOrCompleter match {
1231-
case info: TypeParamsCompleter => info.completerTypeParams(symbol)
1232-
case _ => typeParamsFromDecls
1231+
else {
1232+
val di = initial
1233+
if (this ne di) di.typeParams
1234+
else infoOrCompleter match {
1235+
case info: TypeParamsCompleter => info.completerTypeParams(symbol)
1236+
case _ => typeParamsFromDecls
1237+
}
12331238
}
12341239
myTypeParams
12351240
}

src/dotty/tools/dotc/transform/SelectStatic.scala

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,21 @@ class SelectStatic extends MiniPhaseTransform with IdentityDenotTransformer { th
1919
import ast.tpd._
2020

2121
override def phaseName: String = "selectStatic"
22-
private val isPackage = FlagConjunction(PackageCreationFlags.bits)
2322

2423
override def transformSelect(tree: tpd.Select)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
2524
val sym = tree.symbol
26-
val r1 =
27-
if (!sym.is(isPackage) && !sym.maybeOwner.is(isPackage) &&
28-
(
29-
((sym is Flags.Module) && sym.maybeOwner.isStaticOwner) ||
30-
(sym is Flags.JavaStatic) ||
31-
(sym.maybeOwner is Flags.ImplClass) ||
32-
sym.hasAnnotation(ctx.definitions.ScalaStaticAnnot)
33-
)
34-
)
35-
if (!tree.qualifier.symbol.is(JavaModule) && !tree.qualifier.isType)
36-
Block(List(tree.qualifier), ref(sym))
37-
else tree
25+
def isStaticMember =
26+
(sym is Flags.Module) && sym.initial.maybeOwner.initial.isStaticOwner ||
27+
(sym is Flags.JavaStatic) ||
28+
(sym.maybeOwner is Flags.ImplClass) ||
29+
sym.hasAnnotation(ctx.definitions.ScalaStaticAnnot)
30+
val isStaticRef = !sym.is(Package) && !sym.maybeOwner.is(Package) && isStaticMember
31+
val tree1 =
32+
if (isStaticRef && !tree.qualifier.symbol.is(JavaModule) && !tree.qualifier.isType)
33+
Block(List(tree.qualifier), ref(sym))
3834
else tree
3935

40-
normalize(r1)
36+
normalize(tree1)
4137
}
4238

4339
private def normalize(t: Tree)(implicit ctx: Context) = t match {

0 commit comments

Comments
 (0)