Skip to content

Commit debc5fd

Browse files
committed
SelectStatic: do not create blocks that are qualifier of select\apply
Blocks are not denoting trees(why aren't they?) For now, I'm fixing this using a quick fix. For future, it may make sense to discuss this on dotty meeting and make blocks be a Denoting tree and return denotation of expo. Another option is to move regularisation logic into tree transformers.
1 parent a1a35c9 commit debc5fd

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

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

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dotty.tools.dotc
22
package transform
33

4+
import dotty.tools.dotc.ast.Trees._
45
import dotty.tools.dotc.ast.tpd
56
import dotty.tools.dotc.core.Contexts.Context
67
import dotty.tools.dotc.core.DenotTransformers.IdentityDenotTransformer
@@ -23,17 +24,32 @@ class SelectStatic extends MiniPhaseTransform with IdentityDenotTransformer { th
2324

2425
override def transformSelect(tree: tpd.Select)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
2526
val sym = tree.symbol
26-
if (!sym.is(isPackage) && !sym.maybeOwner.is(isPackage) &&
27-
(
28-
((sym is Flags.Module) && sym.maybeOwner.isStaticOwner) ||
29-
(sym is Flags.JavaStatic) ||
30-
(sym.maybeOwner is Flags.ImplClass) ||
31-
sym.hasAnnotation(ctx.definitions.ScalaStaticAnnot)
32-
)
33-
)
34-
if (!tree.qualifier.symbol.is(JavaModule))
35-
Block(List(tree.qualifier), ref(sym))
27+
val r1 =
28+
if (!sym.is(isPackage) && !sym.maybeOwner.is(isPackage) &&
29+
(
30+
((sym is Flags.Module) && sym.maybeOwner.isStaticOwner) ||
31+
(sym is Flags.JavaStatic) ||
32+
(sym.maybeOwner is Flags.ImplClass) ||
33+
sym.hasAnnotation(ctx.definitions.ScalaStaticAnnot)
34+
)
35+
)
36+
if (!tree.qualifier.symbol.is(JavaModule))
37+
Block(List(tree.qualifier), ref(sym))
38+
else tree
3639
else tree
37-
else tree
40+
41+
normalize(r1)
42+
}
43+
44+
private def normalize(t: Tree)(implicit ctx: Context) = t match {
45+
case Select(Block(stats, qual), nm) =>
46+
Block(stats, Select(qual, nm))
47+
case Apply(Block(stats, qual), nm) =>
48+
Block(stats, Apply(qual, nm))
49+
case _ => t
50+
}
51+
52+
override def transformApply(tree: tpd.Apply)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
53+
normalize(tree)
3854
}
3955
}

0 commit comments

Comments
 (0)