Change Signature: Introduce variable for expression which can't be safely copied in the course of argument substitution

This commit is contained in:
Alexey Sedunov
2015-04-27 15:39:55 +03:00
parent 14f63cdce5
commit 7831e75955
17 changed files with 267 additions and 42 deletions
@@ -0,0 +1,12 @@
// WITH_DEFAULT_VALUE: false
class T(val t: Int)
fun foo(a: Int): Int {
return <selection>T(a + 1)</selection>.t / 2
}
fun bar(x: Int = foo(T(2).t))
fun test() {
foo(T(2).t)
}
@@ -0,0 +1,13 @@
// WITH_DEFAULT_VALUE: false
class T(val t: Int)
fun foo(t: T): Int {
return t.t / 2
}
fun bar(x: Int = foo(T(T(2).t + 1)))
fun test() {
val i = T(2).t
foo(T(i + 1))
}
@@ -0,0 +1,9 @@
// WITH_DEFAULT_VALUE: false
fun foo(a: Int, b: Int): Int {
return <selection>a * b</selection> / 2
}
fun test() {
foo(1.plus(2), 3.minus(4))
}
@@ -0,0 +1,9 @@
// WITH_DEFAULT_VALUE: false
fun foo(i: Int): Int {
return i / 2
}
fun test() {
foo(1.plus(2) * 3.minus(4))
}
@@ -0,0 +1,22 @@
// WITH_DEFAULT_VALUE: false
class T(val t: Int)
open class A {
constructor(): this(1)
constructor(a: Int) {
val x = <selection>T(a + 1)</selection>.t / 2
}
}
class B: A {
constructor(n: Int): super(n + 1)
}
class C: A(1) {
}
fun test() {
A(2)
}
@@ -0,0 +1,22 @@
// WITH_DEFAULT_VALUE: false
class T(val t: Int)
open class A {
constructor(): this(T(1 + 1))
constructor(t: T) {
val x = t.t / 2
}
}
class B: A {
constructor(n: Int): super(T(n + 1 + 1))
}
class C: A(T(1 + 1)) {
}
fun test() {
A(T(2 + 1))
}
@@ -7,12 +7,14 @@ class A(val a: Int) {
}
fun test() {
A(1).foo(a + A(1).a)
val a1 = A(1)
a1.foo(a + a1.a)
}
}
fun test() {
val t = with(A(1)) {
A(2).foo(a + A(2).a)
val a = A(2)
a.foo(this.a + a.a)
}
}
@@ -8,9 +8,13 @@ class A(val a: Int) {
}
fun test() {
A(1).foo(A(1).a + A(2).a)
val a = A(1)
val a1 = A(2)
a.foo(a.a + a1.a)
with(A(1)) {
foo(a + A(2).a)
this.foo(a + A(2).a)
val a1 = A(2)
foo(this.a + a1.a)
val a = A(2)
this.foo(this.a + a.a)
}
}
@@ -8,9 +8,13 @@ class A(val a: Int) {
}
fun test() {
A(1).foo(A(1).a + A(2).a)
val a = A(1)
val a1 = A(2)
a.foo(a.a + a1.a)
with(A(1)) {
foo(a + A(2).a)
this.foo(a + A(2).a)
val a1 = A(2)
foo(this.a + a1.a)
val a = A(2)
this.foo(this.a + a.a)
}
}
@@ -0,0 +1,10 @@
// WITH_DEFAULT_VALUE: false
fun foo(a: Int, b: Int): Int {
return <selection>a * b</selection> / 2
}
fun test() {
var x = 1
foo(++x, x++)
}
@@ -0,0 +1,12 @@
// WITH_DEFAULT_VALUE: false
fun foo(i: Int): Int {
return i / 2
}
fun test() {
var x = 1
val i = ++x
val i1 = x++
foo(i * i1)
}