File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -203,7 +203,7 @@ class FirstTransform extends MiniPhaseTransform with InfoTransformer with Annota
203
203
constToLiteral(tree)
204
204
205
205
override def transformApply (tree : Apply )(implicit ctx : Context , info : TransformerInfo ) =
206
- constToLiteral(tree)
206
+ constToLiteral(foldCondition( tree) )
207
207
208
208
override def transformTyped (tree : Typed )(implicit ctx : Context , info : TransformerInfo ) =
209
209
constToLiteral(tree)
@@ -217,6 +217,20 @@ class FirstTransform extends MiniPhaseTransform with InfoTransformer with Annota
217
217
case _ => tree
218
218
}
219
219
220
+ private def foldCondition (tree : Apply )(implicit ctx : Context ) = tree.fun match {
221
+ case Select (x @ Literal (Constant (c : Boolean )), op) =>
222
+ tree.args match {
223
+ case y :: Nil if y.tpe.widen.isRef(defn.BooleanClass ) =>
224
+ op match {
225
+ case nme.ZAND => if (c) y else x
226
+ case nme.ZOR => if (c) x else y
227
+ case _ => tree
228
+ }
229
+ case _ => tree
230
+ }
231
+ case _ => tree
232
+ }
233
+
220
234
// invariants: all modules have companion objects
221
235
// all types are TypeTrees
222
236
// all this types are explicit
You can’t perform that action at this time.
0 commit comments