aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/PostTyper.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools/dotc/transform/PostTyper.scala')
-rw-r--r--src/dotty/tools/dotc/transform/PostTyper.scala45
1 files changed, 9 insertions, 36 deletions
diff --git a/src/dotty/tools/dotc/transform/PostTyper.scala b/src/dotty/tools/dotc/transform/PostTyper.scala
index 650bc4968..b72785dce 100644
--- a/src/dotty/tools/dotc/transform/PostTyper.scala
+++ b/src/dotty/tools/dotc/transform/PostTyper.scala
@@ -77,42 +77,11 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
}
/** Check bounds of AppliedTypeTrees.
- * Replace constant expressions with Literal nodes.
- * Note: Demanding idempotency instead of purity in literalize is strictly speaking too loose.
- * Example
- *
- * object O { final val x = 42; println("43") }
- * O.x
- *
- * Strictly speaking we can't replace `O.x` with `42`. But this would make
- * most expressions non-constant. Maybe we can change the spec to accept this
- * kind of eliding behavior. Or else enforce true purity in the compiler.
- * The choice will be affected by what we will do with `inline` and with
- * Singleton type bounds (see SIP 23). Presumably
- *
- * object O1 { val x: Singleton = 42; println("43") }
- * object O2 { inline val x = 42; println("43") }
- *
- * should behave differently.
- *
- * O1.x should have the same effect as { println("43"); 42 }
- *
- * whereas
- *
- * O2.x = 42
- *
- * Revisit this issue once we have implemented `inline`. Then we can demand
- * purity of the prefix unless the selection goes to an inline val.
*/
- private def normalizeTree(tree: Tree)(implicit ctx: Context): Tree =
- if (tree.isType) {
- Checking.typeCheck(tree)
- tree
- }
- else tree.tpe.widenTermRefExpr match {
- case ConstantType(value) if isIdempotentExpr(tree) => Literal(value)
- case _ => tree
- }
+ private def normalizeTree(tree: Tree)(implicit ctx: Context): Tree = {
+ if (tree.isType) Checking.typeCheck(tree)
+ tree
+ }
/** If the type of `tree` is a TermRefWithSignature with an underdefined
* signature, narrow the type by re-computing the signature (which should
@@ -158,7 +127,11 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
case pkg: PackageClassDenotation if !tree.symbol.maybeOwner.is(Package) =>
transformSelect(cpy.Select(tree)(qual select pkg.packageObj.symbol, tree.name), targs)
case _ =>
- superAcc.transformSelect(super.transform(tree), targs)
+ val tree1 = super.transform(tree)
+ constToLiteral(tree1) match {
+ case _: Literal => tree1
+ case _ => superAcc.transformSelect(tree1, targs)
+ }
}
}