Fix code inlining for expression body with multiple occurrences

So #KT-17022 Fixed
This commit is contained in:
Mikhail Glukhikh
2017-03-22 22:24:38 +03:00
parent 96846d0b52
commit 081caadec1
7 changed files with 64 additions and 19 deletions
@@ -0,0 +1,4 @@
fun <caret>sqr(x: Double) = x * x
fun bisqr(x: Double) = sqr(sqr(x))
@@ -0,0 +1,4 @@
fun bisqr(x: Double): Double {
val x1 = x * x
return x1 * x1
}
@@ -1,8 +1,8 @@
class Point(val x: Double, val y: Double) {
// After sqr inlining, only first usage of sqr is replaced
fun distance(other: Point): Double {
val x1 = x - other.x
// See KT-17022
return Math.sqrt(x1 * x1 + sqr(y - other.y))
val x1 = y - other.y
val x2 = x - other.x
return Math.sqrt(x2 * x2 + x1 * x1)
}
}