diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AndOr.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AndOr.jet new file mode 100644 index 00000000000..a2272cfd94c --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/AndOr.jet @@ -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(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) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayAccess.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayAccess.jet new file mode 100644 index 00000000000..3d178c3f5dd --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ArrayAccess.jet @@ -0,0 +1,13 @@ +fun bar(x: Int): Int = x + 1 + +fun foo() { + val x: Int? = null + val a = Array(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]; +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpression.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpression.jet new file mode 100644 index 00000000000..e64572a063c --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/BinaryExpression.jet @@ -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) x else x) + if (x != null) bar(x + x/(x-x*x)) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DeepIf.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DeepIf.jet new file mode 100644 index 00000000000..5373ed1f4d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DeepIf.jet @@ -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(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) + } + } + +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhile.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhile.jet new file mode 100644 index 00000000000..7117aeb2c1c --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhile.jet @@ -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) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Elvis.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Elvis.jet new file mode 100644 index 00000000000..fcfdbb7b7b7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Elvis.jet @@ -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) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.jet new file mode 100644 index 00000000000..94d44069aec --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.jet @@ -0,0 +1,13 @@ +fun bar(x: Int) = x + 1 + +fun foo() { + val x: Int? = null + + bar(x) + if (x != null) bar(x!!) + if (x == null) bar(x!!) + if (x != null) else bar(x!!) + if (x == null) else bar(x!!) + if (x != null) bar(x!!) else bar(x!!) + if (x == null) bar(x!!) else bar(x!!) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/For.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/For.jet new file mode 100644 index 00000000000..aa1ef31839c --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/For.jet @@ -0,0 +1,24 @@ +import java.util.HashMap + +fun bar(x: Int): Int = x + 1 + +fun foo() { + val x: Int? = null + val a = Array(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) + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/FunctionLiteral.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/FunctionLiteral.jet new file mode 100644 index 00000000000..b78bfc8489f --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/FunctionLiteral.jet @@ -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) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElse.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElse.jet new file mode 100644 index 00000000000..bc1e14b7dab --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElse.jet @@ -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!!) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElseBothInvalid.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElseBothInvalid.jet new file mode 100644 index 00000000000..37f20e95089 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/IfThenElseBothInvalid.jet @@ -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+ + } + else { + if (x == null) return + 2+ + } + bar(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ObjectExpression.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ObjectExpression.jet new file mode 100644 index 00000000000..74ed7fbbdc0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ObjectExpression.jet @@ -0,0 +1,10 @@ +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 + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/QualifiedExpression.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/QualifiedExpression.jet new file mode 100644 index 00000000000..94c36bb42c2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/QualifiedExpression.jet @@ -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) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.jet new file mode 100644 index 00000000000..23f0379d1a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Return.jet @@ -0,0 +1,12 @@ +fun bar(x: Int): Int = x + 1 + +fun foo(): Int { + val x: Int? = null + + bar(x) + if (x != null) return x + if (x == null) return if (x != null) x else x + if (x == null) return x + if (x != null) return if (x == null) x else x + return x +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ThisSuper.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ThisSuper.jet new file mode 100644 index 00000000000..c2b4ee9fdd2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ThisSuper.jet @@ -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)) + } +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Throw.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Throw.jet new file mode 100644 index 00000000000..e1e2ce8fd57 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Throw.jet @@ -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(x) + if (x == null) return + throw bar(x) + throw bar(x) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryCatch.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryCatch.jet new file mode 100644 index 00000000000..f3f8ce0347c --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryCatch.jet @@ -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) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/UnaryExpression.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/UnaryExpression.jet new file mode 100644 index 00000000000..8803f8d30bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/UnaryExpression.jet @@ -0,0 +1,14 @@ +fun bar(x: Int): Int = x + 1 +fun baz(b: Boolean): Boolean = !b + +fun foo() { + val x: Int? = null + + bar(-x) + if (x != null) bar(-x) + bar(-x) + + val b: Boolean? = null + baz(!b) + if (b != null) baz(!b) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/When.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/When.jet new file mode 100644 index 00000000000..5582e7b2346 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/When.jet @@ -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) +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/While.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/While.jet new file mode 100644 index 00000000000..8cf3c7b7df3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/While.jet @@ -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) +}