[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// KT-7186: False "Type mismatch" error
|
||||
|
||||
fun indexOfMax(a: IntArray): Int? {
|
||||
var maxI: Int? = null
|
||||
a.forEachIndexed { i, value ->
|
||||
if (maxI == null || value >= a[maxI]) {
|
||||
maxI = i
|
||||
}
|
||||
}
|
||||
return maxI
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// KT-7186: False "Type mismatch" error
|
||||
|
||||
fun indexOfMax(a: IntArray): Int? {
|
||||
var maxI: Int? = 0
|
||||
a.forEachIndexed { i, value ->
|
||||
if (value >= a[maxI]) {
|
||||
maxI = i
|
||||
}
|
||||
else if (value < 0) {
|
||||
maxI = null
|
||||
}
|
||||
}
|
||||
return maxI
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
val test: Int = listOf<Any>().map {
|
||||
when (it) {
|
||||
is Int -> it
|
||||
else -> throw AssertionError()
|
||||
}
|
||||
}.sum()
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class My(val x: Int?) {
|
||||
val y: Int? by lazy {
|
||||
var z = x
|
||||
while (z != null) {
|
||||
z = z.hashCode()
|
||||
if (z < 0) return@lazy z
|
||||
if (z == 0) z = null
|
||||
}
|
||||
return@lazy null
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// KT-9051: Allow smart cast for captured variables if they are not modified
|
||||
|
||||
fun foo(y: String) {
|
||||
var x: String? = null
|
||||
y.let { x = it }
|
||||
x.length // Smart cast is not possible
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// KT-9051: Allow smart cast for captured variables if they are not modified
|
||||
|
||||
fun foo(y: String?) {
|
||||
var x: String? = null
|
||||
y?.let { x = it }
|
||||
x.<!INAPPLICABLE_CANDIDATE!>length<!> // Smart cast is not possible
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// KT-9051: Allow smart cast for captured variables if they are not modified
|
||||
|
||||
fun foo(y: String?) {
|
||||
var x: String? = ""
|
||||
if (x != null) {
|
||||
y?.let { x = null }
|
||||
x.length // Smart cast is not possible
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// KT-9051: Allow smart cast for captured variables if they are not modified
|
||||
|
||||
fun bar(z: String?) = z
|
||||
|
||||
fun foo(y: String?) {
|
||||
var x: String? = ""
|
||||
if (x != null) {
|
||||
bar(y?.let { x = null; it }).<!INAPPLICABLE_CANDIDATE!>length<!>
|
||||
x.length // Smart cast is not possible
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// KT-9051: Allow smart cast for captured variables if they are not modified
|
||||
|
||||
fun foo(y: String?) {
|
||||
var x: String? = null
|
||||
if (x != null) {
|
||||
y?.let { x = it }
|
||||
x.length // not-null or not-null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// KT-9051: Allow smart cast for captured variables if they are not modified
|
||||
|
||||
fun foo(y: String?) {
|
||||
var x: String? = ""
|
||||
if (x != null) {
|
||||
y?.let { x != y }
|
||||
// x is not changed, smart cast is possible
|
||||
x.length
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// Based on KT-9033
|
||||
fun f(s: String) = s
|
||||
|
||||
fun foo(s: String?) {
|
||||
s?.let { f(s) }
|
||||
s?.let { f(it) }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// See KT-9529 Smart cast causes code to be incompilable
|
||||
|
||||
fun <T : Any> foo(o: T): Collection<T> {
|
||||
if (o is String) {
|
||||
return listOf(o)
|
||||
}
|
||||
return listOf(o)
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fun foo(y: String?) {
|
||||
var x: String? = ""
|
||||
if (x != null) {
|
||||
with(y?.let { x = null; it }) {
|
||||
this.length
|
||||
x.length
|
||||
}
|
||||
x.length
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user