[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -USELESS_ELVIS
|
||||
|
||||
fun test() {
|
||||
<!INAPPLICABLE_CANDIDATE!>bar<!>(if (true) {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
})
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>bar<!>(1 ?: 2)
|
||||
}
|
||||
|
||||
fun bar(s: String) = s
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
package a
|
||||
|
||||
interface A
|
||||
fun doList(l: List<Int>) = l
|
||||
fun doInt(i: Int) = i
|
||||
fun getList(): List<Int>? = null
|
||||
fun <T> strangeList(f: (T) -> Unit): List<T> = throw Exception("$f")
|
||||
fun <T: A> emptyListOfA(): List<T> = throw Exception()
|
||||
|
||||
//-------------------------------
|
||||
|
||||
fun testElvis(a: Int?, b: Int?) {
|
||||
if (a != null) {
|
||||
doInt(b ?: a)
|
||||
}
|
||||
doList(getList() ?: emptyListOfA()) //should be an error
|
||||
doList(getList() ?: strangeList { doInt(it) }) //lambda was not analyzed
|
||||
}
|
||||
|
||||
|
||||
fun testDataFlowInfo1(a: Int?, b: Int?) {
|
||||
val c: Int = a ?: b!!
|
||||
doInt(c)
|
||||
// b is nullable if a != null
|
||||
b <!INAPPLICABLE_CANDIDATE!>+<!> 1
|
||||
}
|
||||
|
||||
fun testDataFlowInfo2(a: Int?, b: Int?) {
|
||||
doInt(a ?: b!!)
|
||||
// b is nullable if a != null
|
||||
b <!INAPPLICABLE_CANDIDATE!>+<!> 1
|
||||
}
|
||||
|
||||
fun testTypeMismatch(a: String?, b: Any) {
|
||||
<!INAPPLICABLE_CANDIDATE!>doInt<!>(a ?: b)
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
package a
|
||||
|
||||
interface A
|
||||
|
||||
fun <T>id(t: T): T = t
|
||||
fun doList(l: List<Int>) = l
|
||||
fun doInt(i: Int) = i
|
||||
|
||||
fun <T> strangeNullableList(f: (T) -> Unit): List<T>? = throw Exception()
|
||||
fun <T: A> emptyNullableListOfA(): List<T>? = null
|
||||
|
||||
//-------------------------------
|
||||
|
||||
fun testExclExcl() {
|
||||
doList(emptyNullableListOfA()!!) //should be an error here
|
||||
val l: List<Int> = id(emptyNullableListOfA()!!)
|
||||
|
||||
doList(strangeNullableList { doInt(it) }!!) //lambda should be analyzed (at completion phase)
|
||||
}
|
||||
|
||||
fun testDataFlowInfoAfterExclExcl(a: Int?) {
|
||||
doInt(a!!)
|
||||
a + 1
|
||||
}
|
||||
|
||||
fun testUnnecessaryExclExcl(a: Int) {
|
||||
doInt(a!!) //should be warning
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun <T: Any> foo(f: (T) -> Unit): T? = null // T is used only as return type
|
||||
fun test() {
|
||||
val x = foo { it checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }} ?: "" // foo() is inferred as foo<String>, which isn't very good
|
||||
val y: Any = foo { it checkType { _<Any>() } } ?: "" // but for now it's fixed by specifying expected type
|
||||
}
|
||||
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
interface A
|
||||
interface B
|
||||
|
||||
interface C: A, B
|
||||
interface D: A, B
|
||||
interface E: A, B
|
||||
|
||||
fun foo(c: C?, d: D?, e: E?) {
|
||||
val test1: A? = c ?: d ?: e
|
||||
|
||||
val test2: B? = if (false) if (true) c else d else e
|
||||
|
||||
val test3: A? = when {
|
||||
true -> c
|
||||
else -> when {
|
||||
true -> d
|
||||
else -> e
|
||||
}
|
||||
}
|
||||
|
||||
val test4: B? = when (1) {
|
||||
1 -> c
|
||||
2 -> d
|
||||
else -> e
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
package b
|
||||
|
||||
fun bar(i: Int) = i
|
||||
|
||||
fun test(a: Int?, b: Int?) {
|
||||
bar(if (a == null) return else b)
|
||||
}
|
||||
|
||||
fun test(a: Int?, b: Int?, c: Int?) {
|
||||
bar(if (a == null) return else if (b == null) return else c)
|
||||
}
|
||||
|
||||
fun test(a: Any?, b: Any?, c: Int?) {
|
||||
bar(if (a == null) if (b == null) c else return else return)
|
||||
}
|
||||
|
||||
fun test(a: Int?, b: Any?, c: Int?) {
|
||||
bar(if (a == null) {
|
||||
return
|
||||
} else {
|
||||
if (b == null) {
|
||||
return
|
||||
} else {
|
||||
c
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user