Skip to content

Commit 257954c

Browse files
DropNoEffects: fix first bootstrap bug
1 parent e93b499 commit 257954c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

compiler/src/dotty/tools/dotc/transform/localopt/DropNoEffects.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,14 @@ class DropNoEffects(val simplifyPhase: Simplify)(implicit val ctx: Context) exte
123123
rec :: args.map(keepOnlySideEffects)
124124
}
125125
Block(prefix, unitLiteral)
126+
126127
case t @ TypeApply(Select(rec, _), List(testType)) if t.symbol.eq(defn.Any_asInstanceOf) && testType.tpe.widenDealias.typeSymbol.exists =>
127128
val receiverType = TypeErasure.erasure(rec.tpe)
128129
val erazedTestedType = TypeErasure.erasure(testType.tpe)
129130
if (receiverType.derivesFrom(erazedTestedType.typeSymbol))
130-
EmptyTree
131+
rec
131132
else t
133+
132134
case _ => t
133135
}
134136
}

tests/run/drop-no-effects.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
var run = false
4+
5+
val one = {
6+
run = true
7+
1
8+
}.asInstanceOf[Int]
9+
10+
assert(run)
11+
}
12+
}

0 commit comments

Comments
 (0)