[FIR-TEST] Add new testdata generated after changes in previous commit

This commit is contained in:
Dmitriy Novozhilov
2019-12-11 16:16:22 +03:00
parent e9c02a1cca
commit 2536fa0cd5
4578 changed files with 104067 additions and 1 deletions
@@ -0,0 +1,13 @@
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
if (x != null && bar(x) == 0) bar(bar(x))
bar(x)
if (x == null || bar(x) == 0) bar(bar(x))
bar(x)
if (x is Int && bar(x)*bar(x) == bar(x)) bar(x)
bar(x)
}
@@ -0,0 +1,13 @@
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
val a = Array<Int>(3, {0})
if (x != null) bar(a[x]) else bar(a[x])
bar(a[if (x == null) 0 else x])
bar(a[x])
"123"[x];
if (x != null) "123"[x];
}
@@ -0,0 +1,8 @@
// !CHECK_TYPE
fun foo(arr: Array<out Number>): Int {
@Suppress("UNCHECKED_CAST")
val result = (arr as Array<Int>)[0]
checkSubtype<Array<Int>>(arr)
return result
}
@@ -0,0 +1,28 @@
// !CHECK_TYPE
interface G {
operator fun get(x: Int, y: Int): Int = x + y
operator fun set(x: Int, y: Int, value: Int) {}
}
fun foo1(a: Int?, b: G) {
b[a!!, a!!] = a
checkSubtype<Int>(a)
}
fun foo2(a: Int?, b: G) {
b[0, a!!] = a
checkSubtype<Int>(a)
}
fun foo3(a: Int?, b: G) {
val r = b[a!!, a]
checkSubtype<Int>(a)
checkSubtype<Int>(r)
}
fun foo4(a: Int?, b: G) {
val r = b[0, a!!]
checkSubtype<Int>(a)
checkSubtype<Int>(r)
}
@@ -0,0 +1,11 @@
// !CHECK_TYPE
fun foo1(a: Int?, b: Array<Array<Int>>) {
b[a!!][a!!] = a
checkSubtype<Int>(a)
}
fun foo2(a: Int?, b: Array<Array<Int>>) {
b[0][a!!] = a
checkSubtype<Int>(a)
}
@@ -0,0 +1,17 @@
interface A
interface B : A {
fun foo()
}
fun bar1(a: A) {
var b: B = a as B
a.foo()
b.foo()
}
fun id(b: B) = b
fun bar2(a: A) {
var b: B = id(a as B)
a.foo()
b.foo()
}
@@ -0,0 +1,21 @@
// KT-2825 DataFlowInfo is not retained after assignment
interface A
interface B : A {
fun foo()
}
fun baz(b: B) = b
fun bar1(a: A) {
val b = a as B
a.foo()
b.foo()
}
fun bar2(a: A) {
val b = baz(a as B)
a.foo()
b.foo()
}
@@ -0,0 +1,17 @@
// !CHECK_TYPE
fun bar1(x: Number, y: Int) {
var yy = y
yy += x as Int
checkSubtype<Int>(x)
}
fun bar2(x: Number) {
<!UNRESOLVED_REFERENCE, VARIABLE_EXPECTED!>y<!> += x as Int
checkSubtype<Int>(x)
}
fun bar3(x: Number, y: Array<Int>) {
y[0] += x as Int
checkSubtype<Int>(x)
}
@@ -0,0 +1,12 @@
// !CHECK_TYPE
fun arrayAccessRHS(a: Int?, b: Array<Int>) {
b[0] = a!!
checkSubtype<Int>(a)
}
fun arrayAccessLHS(a: Int?, b: Array<Int>) {
b[a!!] = a
checkSubtype<Int>(a)
}
@@ -0,0 +1,11 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
bar(1 + (if (x == null) 0 else x))
bar(if (x == null) x else x)
if (x != null) bar(x + x/(x-x*x))
}
@@ -0,0 +1,25 @@
// !CHECK_TYPE
fun foo1(x: Number, cond: Boolean): Boolean {
val result = cond && ((x as Int) == 42)
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Int>(x)
return result
}
fun foo2(x: Number, cond: Boolean): Boolean {
val result = ((x as Int) == 42) && cond
checkSubtype<Int>(x)
return result
}
fun foo3(x: Number, cond: Boolean): Boolean {
val result = cond || ((x as Int) == 42)
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Int>(x)
return result
}
fun foo4(x: Number, cond: Boolean): Boolean {
val result = ((x as Int) == 42) || cond
checkSubtype<Int>(x)
return result
}
@@ -0,0 +1,18 @@
// !CHECK_TYPE
interface A
interface B : A
operator fun B.compareTo(b: B) = if (this == b) 0 else 1
fun foo(a: A): Boolean {
val result = (a as B) < a
checkSubtype<B>(a)
return result
}
fun bar(a: A, b: B): Boolean {
val result = b < (a as B)
checkSubtype<B>(a)
return result
}
@@ -0,0 +1,7 @@
// !CHECK_TYPE
fun foo(x: Number): Boolean {
val result = (x as Int) in 1..5
checkSubtype<Int>(x)
return result
}
@@ -0,0 +1,16 @@
// !CHECK_TYPE
fun foo(x: Int?): Int = x!!
fun elvis(x: Number?): Int {
val result = (x as Int?) ?: foo(x)
checkSubtype<Int?>(x)
return result
}
fun elvisWithRHSTypeInfo(x: Number?): Any? {
val result = x ?: x!!
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Int?>(x)
return result
}
@@ -0,0 +1,16 @@
// !CHECK_TYPE
interface A
interface B : A
fun foo1(a: A, b: B): Boolean {
val result = (a as B) == b
checkSubtype<B>(a)
return result
}
fun foo2(a: A, b: B): Boolean {
val result = b == (a as B)
checkSubtype<B>(a)
return result
}
@@ -0,0 +1,15 @@
// !CHECK_TYPE
infix fun Int.compareTo(o: Int) = 0
fun foo(a: Number): Int {
val result = (a as Int) compareTo a
checkSubtype<Int>(a)
return result
}
fun bar(a: Number): Int {
val result = 42 compareTo (a as Int)
checkSubtype<Int>(a)
return result
}
@@ -0,0 +1,18 @@
// !CHECK_TYPE
interface A
interface B : A
operator fun B.plus(b: B) = if (this == b) b else this
fun foo(a: A): B {
val result = (a as B) + a
checkSubtype<B>(a)
return result
}
fun bar(a: A, b: B): B {
val result = b + (a as B)
checkSubtype<B>(a)
return result
}
@@ -0,0 +1,7 @@
// !CHECK_TYPE
fun foo(x: Int?): Boolean {
val result = ((x!! == 0) && (checkSubtype<Int>(x) == 0))
checkSubtype<Int>(x)
return result
}
@@ -0,0 +1,34 @@
// !CHECK_TYPE
fun whileLoop(x: Int?) {
outer@ while (x != 0) {
while (x != 1) {
if (x == 2) continue@outer
}
checkSubtype<Int>(x)
}
checkSubtype<Int>(x)
}
fun doWhileLoop(x: Int?) {
outer@ while (x != 0) {
do {
if (x == 2) continue@outer
} while (x == null)
checkSubtype<Int>(x)
}
checkSubtype<Int>(x)
}
fun whileLoopContinueInnerOuter(x: Int?) {
outer@ while (x != 0) {
inner@ while (x != 1) {
while (x != 2) {
if (x == 3) continue@inner
}
checkSubtype<Int>(x)
}
checkSubtype<Int>(x)
}
checkSubtype<Int>(x)
}
@@ -0,0 +1,31 @@
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
fun bar(x: Int) = x + 1
fun foo() {
val x: Int? = null
if (x != null) {
bar(x)
if (x != null) {
bar(x)
if (1 < 2) bar(x)
if (1 > 2) bar(x)
}
if (x == null) {
bar(x)
}
if (x == null) bar(x) else bar(x)
bar(bar(x))
} else if (x == null) {
bar(x)
if (x != null) {
bar(x)
if (x == null) bar(x)
if (x == null) bar(x) else bar(x)
bar(bar(x) + bar(x))
} else if (x == null) {
bar(x)
}
}
}
@@ -0,0 +1,16 @@
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
do {
bar(x)
} while (x == null)
bar(x)
val y: Int? = null
do {
bar(y)
} while (y != null)
bar(y)
}
@@ -0,0 +1,20 @@
// !CHECK_TYPE
fun simpleDoWhile(x: Int?, y0: Int) {
var y = y0
do {
checkSubtype<Int?>(x)
y++
} while (x!! == y)
checkSubtype<Int>(x)
}
fun doWhileWithBreak(x: Int?, y0: Int) {
var y = y0
do {
checkSubtype<Int?>(x)
y++
if (y > 0) break
} while (x!! == y)
checkSubtype<Int>(x)
}
@@ -0,0 +1,9 @@
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
bar(x ?: 0)
if (x != null) bar(x ?: x)
bar(x)
}
@@ -0,0 +1,24 @@
// !WITH_NEW_INFERENCE
fun bar(x: Int) = x + 1
fun f1(x: Int?) {
bar(x)
if (x != null) bar(x!!)
if (x == null) bar(x!!)
}
fun f2(x: Int?) {
if (x != null) else x!!
}
fun f3(x: Int?) {
if (x != null) bar(x!!) else x!!
}
fun f4(x: Int?) {
if (x == null) x!! else bar(x!!)
}
fun f5(x: Int?) {
if (x == null) else bar(x!!)
}
@@ -0,0 +1,22 @@
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
val a = Array<Int>(3, {0})
for (p in a) {
bar(x)
if (x == null) continue
bar(x)
for (q in a) {
bar(x)
if (x == null) bar(x)
}
}
for (p in a) {
bar(x)
if (x == null) break
bar(x)
}
}
@@ -0,0 +1,8 @@
// !CHECK_TYPE
fun foo(arr: Array<Int>?) {
for (x in arr!!) {
checkSubtype<Array<Int>>(arr)
}
checkSubtype<Array<Int>>(arr)
}
@@ -0,0 +1,9 @@
fun bar(x: Int) = x + 1
fun foo() {
val x: Int? = null
fun baz() = bar(x)
fun quux() = if (x != null) bar(x) else baz()
fun quuux() = bar(if (x == null) 0 else x)
}
@@ -0,0 +1,31 @@
// !CHECK_TYPE
fun ifThen(x: Int?) {
if (x!! == 0) {
checkSubtype<Int>(x)
}
checkSubtype<Int>(x)
}
fun ifElse(x: Int?) {
if (x!! == 0) else {
checkSubtype<Int>(x)
}
checkSubtype<Int>(x)
}
fun ifThenElse(x: Int?) {
if (x!! == 0) {
checkSubtype<Int>(x)
} else {
checkSubtype<Int>(x)
}
checkSubtype<Int>(x)
}
fun ifIs(x: Int?, cond: Boolean) {
if ((x is Int) == cond) {
checkSubtype<Int>(x)
}
checkSubtype<Int>(x)
}
@@ -0,0 +1,30 @@
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
bar(if (x == null) 0 else x)
if (x == null) {
bar(x)
return
} else {
bar(x)
}
bar(x)
val y: Int? = null
if (y is Int) {
bar(y)
} else {
bar(y)
return
}
bar(y)
val z: Int? = null
if (z != null) bar(z)
bar(z)
bar(z!!)
if (z != null) bar(z!!)
}
@@ -0,0 +1,16 @@
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
bar(x)
if (x != 2) {
if (x == null) return
2<!AMBIGUITY!>+<!><!SYNTAX!><!>
}
else {
if (x == null) return
2<!AMBIGUITY!>+<!><!SYNTAX!><!>
}
bar(x)
}
@@ -0,0 +1,8 @@
// !CHECK_TYPE
fun foo(x: Number) {
if ((x as Int) is Int) {
checkSubtype<Int>(x)
}
checkSubtype<Int>(x)
}
@@ -0,0 +1,32 @@
// !CHECK_TYPE
fun noUselessDataFlowInfoCreation(x: Number) {
if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) {
if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) {
if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) {
if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) {
if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) {
} } } } } } } } } } } } } } } } } } } } } } } } }
}
fun dataFlowInfoAnd(a: Array<Number>) {
if (a[0] is Int) { if (a[1] is Int) { if (a[2] is Int) { if (a[3] is Int) { if (a[4] is Int) {
if (a[5] is Int) { if (a[6] is Int) { if (a[7] is Int) { if (a[8] is Int) { if (a[9] is Int) {
if (a[10] is Int) { if (a[11] is Int) { if (a[12] is Int) { if (a[13] is Int) { if (a[14] is Int) {
if (a[15] is Int) { if (a[16] is Int) { if (a[17] is Int) { if (a[18] is Int) { if (a[19] is Int) {
if (a[20] is Int) { if (a[21] is Int) { if (a[22] is Int) { if (a[23] is Int) { if (a[24] is Int) {
if (a[25] is Int) { if (a[26] is Int) { if (a[27] is Int) { if (a[28] is Int) { if (a[29] is Int) {
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Int>(a[0])
} } } } } } } } } } } } } } } } } } } } } } } } } } } } } }
}
fun dataFlowInfoOr(a: Array<Number>) {
if (a[0] is Int || a[1] is Int || a[2] is Int || a[3] is Int || a[4] is Int || a[5] is Int || a[6] is Int || a[7] is Int || a[8] is Int || a[9] is Int ||
a[10] is Int || a[11] is Int || a[12] is Int || a[13] is Int || a[14] is Int || a[15] is Int || a[16] is Int || a[17] is Int || a[18] is Int || a[19] is Int ||
a[20] is Int || a[21] is Int || a[22] is Int || a[23] is Int || a[24] is Int || a[25] is Int || a[26] is Int || a[27] is Int || a[28] is Int || a[29] is Int ||
a[30] is Int || a[31] is Int || a[32] is Int || a[33] is Int || a[34] is Int || a[35] is Int || a[36] is Int || a[37] is Int || a[38] is Int || a[39] is Int ||
a[40] is Int || a[41] is Int || a[42] is Int || a[43] is Int || a[44] is Int || a[45] is Int || a[46] is Int || a[47] is Int || a[48] is Int || a[49] is Int ||
a[50] is Int || a[51] is Int || a[52] is Int || a[53] is Int || a[54] is Int || a[55] is Int || a[56] is Int || a[57] is Int || a[58] is Int || a[59] is Int) {
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Int>(a[0])
}
}
@@ -0,0 +1,9 @@
// !CHECK_TYPE
operator fun Int.component1() = "a"
fun foo(a: Number) {
val (x) = a as Int
checkSubtype<Int>(a)
checkSubtype<String>(x)
}
@@ -0,0 +1,12 @@
// !WITH_NEW_INFERENCE
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
val a = object {
fun baz() = bar(if (x == null) 0 else x)
fun quux(): Int = if (x == null) x else x
}
}
@@ -0,0 +1,13 @@
fun baz(x: Int): Int = x + 1
class A {
fun bar(x: Int) = baz(x)
}
fun foo() {
val x: Int? = null
A().bar(x)
if (x == null) return
A().bar(x)
}
@@ -0,0 +1,18 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
fun bar(x: Int): Int = x + 1
fun foo(): Int {
val x: Int? = null
bar(x)
if (x != null) return x
val y: Int? = null
if (y == null) return if (y != null) y else y
val z: Int? = null
if (z != null) return if (z == null) z else z
return z
}
@@ -0,0 +1,8 @@
// !CHECK_TYPE
fun foo(x: Number, y: String?): String {
val result = "abcde $x ${x as Int} ${y!!} $x $y"
checkSubtype<Int>(x)
checkSubtype<String>(y)
return result
}
@@ -0,0 +1,21 @@
open class Base {
fun bar(x: Int): Int = x + 1
}
class Derived : Base() {
fun baz(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
super.bar(x)
this.baz(x)
if (x == null) return
super.bar(x)
this.baz(x)
val y: Int? = null
if (y != null) super.bar(this.baz(y))
else this.baz(super.bar(y))
}
}
@@ -0,0 +1,9 @@
fun bar(x: Int): RuntimeException = RuntimeException(x.toString())
fun foo() {
val x: Int? = null
if (x == null) throw bar(x)
throw bar(x)
throw bar(x)
}
@@ -0,0 +1,15 @@
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
bar(x)
if (x == null) return
try {
bar(x)
}
catch (e: Exception) {
bar(x)
}
bar(x)
}
@@ -0,0 +1,21 @@
// !CHECK_TYPE
fun tryFinally(x: Int?) {
try {
} finally {
x!!
}
checkSubtype<Int>(x)
}
fun tryCatchFinally(x: Int?) {
try {
x!!
} catch (e: Exception) {
x!!
} finally {
checkSubtype<Int>(x)
x!!
}
checkSubtype<Int>(x)
}
@@ -0,0 +1,14 @@
fun bar(x: Int): Int = x + 1
fun baz(b: Boolean): Boolean = !b
fun foo() {
val x: Int? = null
bar(<!INAPPLICABLE_CANDIDATE!>-<!>x)
if (x != null) bar(-x)
bar(<!INAPPLICABLE_CANDIDATE!>-<!>x)
val b: Boolean? = null
baz(<!INAPPLICABLE_CANDIDATE!>!<!>b)
if (b != null) baz(!b)
}
@@ -0,0 +1,18 @@
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
if (x != null) {
when (x) {
0 -> bar(x)
else -> {}
}
}
when (x) {
0 -> { if (x == null) return }
else -> { if (x == null) return }
}
bar(x)
}
@@ -0,0 +1,26 @@
// !CHECK_TYPE
fun foo(x: Number, y: Int) {
when (x) {
x as Int -> checkSubtype<Int>(x)
y -> {}
else -> {}
}
checkSubtype<Int>(x)
}
fun bar(x: Number) {
when (x) {
x as Int -> checkSubtype<Int>(x)
else -> {}
}
checkSubtype<Int>(x)
}
fun whenWithoutSubject(x: Number) {
when {
(x as Int) == 42 -> checkSubtype<Int>(x)
else -> {}
}
checkSubtype<Int>(x)
}
@@ -0,0 +1,26 @@
// !CHECK_TYPE
fun foo(x: Number, y: Int) {
when (x) {
is Int -> checkSubtype<Int>(x)
y -> {}
else -> {}
}
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Int>(x)
}
fun bar(x: Number) {
when (x) {
is Int -> checkSubtype<Int>(x)
else -> {}
}
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Int>(x)
}
fun whenWithoutSubject(x: Number) {
when {
(x is Int) -> checkSubtype<Int>(x)
else -> {}
}
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Int>(x)
}
@@ -0,0 +1,15 @@
// !CHECK_TYPE
fun foo(x: Int, list: List<Int>?) {
when (x) {
in list!! -> checkSubtype<List<Int>>(list)
else -> {}
}
}
fun whenWithoutSubject(x: Int, list: List<Int>?) {
when {
x in list!! -> checkSubtype<List<Int>>(list)
else -> {}
}
}
@@ -0,0 +1,8 @@
// !CHECK_TYPE
fun foo(x: Number) {
when (x as Int) {
else -> checkSubtype<Int>(x)
}
checkSubtype<Int>(x)
}
@@ -0,0 +1,22 @@
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
while (x == null) {
bar(x)
}
bar(x)
val y: Int? = null
while (y != null) {
bar(y)
}
bar(y)
val z: Int? = null
while (z == null) {
bar(z)
break
}
bar(z)
}
@@ -0,0 +1,26 @@
// !CHECK_TYPE
fun simpleWhile(x: Int?, y0: Int) {
var y = y0
while (x!! == y) {
checkSubtype<Int>(x)
y++
}
checkSubtype<Int>(x)
}
fun whileWithBreak(x: Int?, y0: Int) {
var y = y0
while (x!! == y) {
checkSubtype<Int>(x)
break
}
checkSubtype<Int>(x)
}
fun whileWithNoCondition(x: Int?) {
while (<!SYNTAX!><!>) {
x!!
}
checkSubtype<Int>(x)
}
@@ -0,0 +1,9 @@
//KT-4332 when/smartcast underperforms
fun testWhen(t: String?, x: String?): Int {
return when {
t == null -> 0
x == null -> t.length // Wrong error report here. t can be inferred as not-null. (And it actually does if you replace when with if/else if)
else -> (t + x).length
}
}
@@ -0,0 +1,11 @@
//KT-5155 Auto-casts do not work with when
fun foo(s: String?) {
when {
s == null -> 1
s.foo() -> 2
else -> 3
}
}
fun String.foo() = true
@@ -0,0 +1,13 @@
//KT-5182 Data flow info is lost for 'when' branches
open class A
class B: A() {
fun foo() = 1
}
fun foo(a: A) = when {
a !is B -> 2
true -> a.foo() //'foo' is unresolved, smart cast doesn't work
else -> a.foo()
}
@@ -0,0 +1,16 @@
interface B {
fun bar() {}
}
class C() {
fun bar() {
}
}
fun test(a : Any?) {
if (a is B) {
if (a is C) {
a.<!AMBIGUITY!>bar<!>();
}
}
}
@@ -0,0 +1,86 @@
// FILE: a.kt
package example.ns
val y : Any? = 2
// FILE: b.kt
package example
import example.ns.y
object Obj {
val y : Any? = 2
}
class AClass() {
companion object {
val y : Any? = 2
}
}
val x : Any? = 1
fun Any?.vars(a: Any?) : Int {
var b: Int = 0
if (example.ns.y is Int) {
b = y
}
if (example.ns.y is Int) {
b = example.ns.y
}
if (Obj.y is Int) {
b = Obj.y
}
if (example.Obj.y is Int) {
b = Obj.y
}
if (AClass.y is Int) {
b = AClass.y
}
if (example.AClass.y is Int) {
b = AClass.y
}
if (x is Int) {
b = x
}
if (example.x is Int) {
b = x
}
if (example.x is Int) {
b = example.x
}
return 1
}
fun Any?.foo() : Int {
if (this is Int)
return this
if (this@foo is Int)
return this
if (this@foo is Int)
return this@foo
if (this is Int)
return this@foo
return 1
}
interface T {}
open class C {
fun foo() {
var t : T? = null
if (this is T) {
t = this
}
if (this is T) {
t = this@C
}
if (this@C is T) {
t = this
}
if (this@C is T) {
t = this@C
}
}
}