aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src/dotty/tools/dotc/transform/FirstTransform.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/transform/FirstTransform.scala9
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala
index 597146514..9e71fda5d 100644
--- a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala
+++ b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala
@@ -31,6 +31,9 @@ import StdNames._
* - eliminates self tree in Template and self symbol in ClassInfo
* - collapsess all type trees to trees of class TypeTree
* - converts idempotent expressions with constant types
+ * - drops branches of ifs using the rules
+ * if (true) A else B --> A
+ * if (false) A else B --> B
*/
class FirstTransform extends MiniPhaseTransform with InfoTransformer with AnnotationTransformer { thisTransformer =>
import ast.tpd._
@@ -187,6 +190,12 @@ class FirstTransform extends MiniPhaseTransform with InfoTransformer with Annota
override def transformBlock(tree: Block)(implicit ctx: Context, info: TransformerInfo) =
constToLiteral(tree)
+ override def transformIf(tree: If)(implicit ctx: Context, info: TransformerInfo) =
+ tree.cond match {
+ case Literal(Constant(c: Boolean)) => if (c) tree.thenp else tree.elsep
+ case _ => tree
+ }
+
// invariants: all modules have companion objects
// all types are TypeTrees
// all this types are explicit