Lift assignment: do not report in cases where argument are of different types #KT-21520 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-09-13 16:38:28 +09:00
committed by Mikhail Glukhikh
parent fcc6395b14
commit 0cd25353bc
9 changed files with 122 additions and 4 deletions
@@ -0,0 +1,9 @@
// WITH_RUNTIME
fun test(b: Boolean, x: Int, y: Int?) {
val list = mutableListOf<Int?>()
<caret>if (b) {
list += x
} else {
list += y
}
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
fun test(b: Boolean, x: Int, y: Int?) {
val list = mutableListOf<Int?>()
list += if (b) {
x
} else {
y
}
}
@@ -0,0 +1,9 @@
// PROBLEM: none
fun test(b: Boolean, x: Long, y: Int) {
var num: Long = 0L
<caret>if (b) {
num += x
} else {
num += y
}
}
@@ -0,0 +1,10 @@
// PROBLEM: none
// ERROR: Type mismatch: inferred type is Long? but Long was expected
fun test(b: Boolean, x: Long, y: Long?) {
var num: Long = 0L
<caret>if (b) {
num += x
} else {
num += y
}
}
@@ -0,0 +1,13 @@
// PROBLEM: none
class C {
operator fun plusAssign(i: Int) {}
operator fun plusAssign(b: Boolean) {}
}
fun f(b: Boolean) {
val c = C()
<caret>if (b)
c += 1
else
c += true
}
@@ -0,0 +1,10 @@
// PROBLEM: none
// WITH_RUNTIME
fun test(b: Boolean) {
val list = mutableListOf<Int>()
<caret>if (b) {
list += 1
} else {
list += mutableListOf(2)
}
}
@@ -0,0 +1,12 @@
// PROBLEM: none
// ERROR: Type mismatch: inferred type is List<Any> but MutableList<Int> was expected
// ERROR: Val cannot be reassigned
// WITH_RUNTIME
fun test(b: Boolean) {
val list = mutableListOf<Int>()
<caret>if (b) {
list += mutableListOf(1)
} else {
list += mutableListOf(2L)
}
}