dataFlowInfoTraversal tests

This commit is contained in:
Alexander Udalov
2012-06-14 17:29:57 +04:00
parent c3420e864e
commit efe70955dd
20 changed files with 316 additions and 0 deletions
@@ -0,0 +1,12 @@
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
if (x != null && bar(x) == 0) bar(bar(x))
bar(<!TYPE_MISMATCH!>x<!>)
if (x == null || bar(x) == 0) bar(bar(<!TYPE_MISMATCH!>x<!>))
bar(<!TYPE_MISMATCH!>x<!>)
if (x is Int && bar(x)*bar(x) == bar(x)) bar(x)
bar(<!TYPE_MISMATCH!>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<!NO_GET_METHOD!>[<!TYPE_MISMATCH!>x<!>]<!>)
bar(a[if (x == null) 0 else x])
bar(a<!NO_GET_METHOD!>[<!TYPE_MISMATCH!>x<!>]<!>)
"123"<!NO_GET_METHOD!>[<!TYPE_MISMATCH!>x<!>]<!>;
if (x != null) "123"[x];
}
@@ -0,0 +1,9 @@
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) <!TYPE_MISMATCH!>x<!> else x)
if (x != null) bar(x + x/(x-x*x))
}
@@ -0,0 +1,30 @@
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(<!TYPE_MISMATCH!>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(<!TYPE_MISMATCH!>x<!>)
}
}
}
@@ -0,0 +1,16 @@
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
do {
bar(<!TYPE_MISMATCH!>x<!>)
} while (x == null)
bar(x)
val y: Int? = null
do {
bar(<!TYPE_MISMATCH!>y<!>)
} while (y != null)
bar(<!TYPE_MISMATCH!>y<!>)
}
@@ -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(<!TYPE_MISMATCH!>x<!>)
}
@@ -0,0 +1,13 @@
fun bar(x: Int) = x + 1
fun foo() {
val x: Int? = null
bar(<!TYPE_MISMATCH!>x<!>)
if (x != null) bar(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
if (x == null) bar(x!!)
if (x != null) else bar(x!!)
if (x == null) else bar(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
if (x != null) bar(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>) else bar(x!!)
if (x == null) bar(x!!) else bar(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
}
@@ -0,0 +1,24 @@
import java.util.HashMap
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
val a = Array<Int>(3, {0})
for (p in a) {
bar(<!TYPE_MISMATCH!>x<!>)
if (x == null) continue
bar(x)
for (q in a) {
bar(x)
if (x == null) bar(x)
}
}
for (p in a) {
bar(<!TYPE_MISMATCH!>x<!>)
if (x == null) break
bar(x)
}
}
@@ -0,0 +1,9 @@
fun bar(x: Int) = x + 1
fun foo() {
val x: Int? = null
fun baz() = bar(<!TYPE_MISMATCH!>x<!>)
fun quux() = if (x != null) bar(x) else baz()
fun quuux() = bar(if (x == null) 0 else 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(<!TYPE_MISMATCH!>x<!>)
return
} else {
bar(x)
}
bar(x)
val y: Int? = null
if (y is Int) {
bar(y)
} else {
bar(<!TYPE_MISMATCH!>y<!>)
return
}
bar(y)
val z: Int? = null
if (z != null) bar(z)
bar(<!TYPE_MISMATCH!>z<!>)
bar(z!!)
if (z != null) bar(z<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
}
@@ -0,0 +1,16 @@
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
bar(<!TYPE_MISMATCH!>x<!>)
if (x != 2) {
if (x == null) return
2+<!SYNTAX!><!>
}
else {
if (x == null) return
2+<!SYNTAX!><!>
}
bar(x)
}
@@ -0,0 +1,10 @@
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
val <!UNUSED_VARIABLE!>a<!> = object {
fun baz() = bar(if (x == null) 0 else x)
fun quux(): Int = if (x == null) <!TYPE_MISMATCH!>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(<!TYPE_MISMATCH!>x<!>)
if (x == null) return
A().bar(x)
}
@@ -0,0 +1,12 @@
fun bar(x: Int): Int = x + 1
fun foo(): Int {
val x: Int? = null
bar(<!TYPE_MISMATCH!>x<!>)
if (x != null) return x
if (x == null) return if (x != null) x else <!TYPE_MISMATCH!>x<!>
if (x == null) return x
if (x != null) return if (x == null) x else x
return x
}
@@ -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(<!TYPE_MISMATCH!>x<!>)
this.baz(<!TYPE_MISMATCH!>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(<!TYPE_MISMATCH!>y<!>))
}
}
@@ -0,0 +1,10 @@
fun bar(x: Int): RuntimeException = RuntimeException(x.toString())
fun foo() {
val x: Int? = null
if (x == null || 1 < 2) throw bar(<!TYPE_MISMATCH!>x<!>)
if (x == null) return
throw bar(x)
throw <!UNREACHABLE_CODE!>bar(x)<!>
}
@@ -0,0 +1,15 @@
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
bar(<!TYPE_MISMATCH!>x<!>)
if (x == null) return
try {
bar(x)
}
catch (e: Exception) {
bar(x)
}
bar(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(<!UNSAFE_CALL!>-<!>x)
if (x != null) bar(-x)
bar(<!UNSAFE_CALL!>-<!>x)
val b: Boolean? = null
baz(<!UNSAFE_CALL!>!<!>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,22 @@
fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
while (x == null) {
bar(<!TYPE_MISMATCH!>x<!>)
}
bar(x)
val y: Int? = null
while (y != null) {
bar(y)
}
bar(<!TYPE_MISMATCH!>y<!>)
val z: Int? = null
while (z == null) {
bar(<!TYPE_MISMATCH!>z<!>)
break
}
bar(<!TYPE_MISMATCH!>z<!>)
}