[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun testCommasAndWhitespaces() {
|
||||
fun bar(i: Int, s: String, x: Any) {}
|
||||
|
||||
bar( 1 , todo() , "" )
|
||||
}
|
||||
|
||||
fun todo(): Nothing = throw Exception()
|
||||
|
||||
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package a
|
||||
|
||||
fun test1() {
|
||||
bar(
|
||||
11,
|
||||
todo(),//comment1
|
||||
""//comment2
|
||||
)
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
bar(11, todo()/*comment1*/, ""/*comment2*/)
|
||||
}
|
||||
fun test3() {
|
||||
bar(11, l@(todo()/*comment*/), "")
|
||||
}
|
||||
|
||||
fun todo(): Nothing = throw Exception()
|
||||
|
||||
fun bar(i: Int, s: String, a: Any) {}
|
||||
|
||||
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
fun testInvoke() {
|
||||
operator fun Nothing.invoke(): Nothing = this
|
||||
todo()()
|
||||
}
|
||||
|
||||
fun testInvokeWithLambda() {
|
||||
operator fun Nothing.invoke(i: Int, f: () -> Int) = f
|
||||
todo()(1){ 42 }
|
||||
}
|
||||
|
||||
fun todo(): Nothing = throw Exception()
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fun test11() {
|
||||
fun Any.bar(i: Int) {}
|
||||
todo().bar(1)
|
||||
}
|
||||
|
||||
fun test12() {
|
||||
fun Any.bar(i: Int) {}
|
||||
todo()?.bar(1)
|
||||
}
|
||||
|
||||
fun todo(): Nothing = throw Exception()
|
||||
Vendored
+168
@@ -0,0 +1,168 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
|
||||
|
||||
fun t1() : Int{
|
||||
return 0
|
||||
1
|
||||
}
|
||||
|
||||
fun t1a() : Int {
|
||||
return
|
||||
return 1
|
||||
1
|
||||
}
|
||||
|
||||
fun t1b() : Int {
|
||||
return 1
|
||||
return 1
|
||||
1
|
||||
}
|
||||
|
||||
fun t1c() : Int {
|
||||
return 1
|
||||
return
|
||||
1
|
||||
}
|
||||
|
||||
fun t2() : Int {
|
||||
if (1 > 2)
|
||||
return 1
|
||||
else return 1
|
||||
1
|
||||
}
|
||||
|
||||
fun t2a() : Int {
|
||||
if (1 > 2) {
|
||||
return 1
|
||||
1
|
||||
} else { return 1
|
||||
2
|
||||
}
|
||||
1
|
||||
}
|
||||
|
||||
fun t3() : Any {
|
||||
if (1 > 2)
|
||||
return 2
|
||||
else return ""
|
||||
1
|
||||
}
|
||||
|
||||
fun t4(a : Boolean) : Int {
|
||||
do {
|
||||
return 1
|
||||
}
|
||||
while (a)
|
||||
1
|
||||
}
|
||||
|
||||
fun t4break(a : Boolean) : Int {
|
||||
do {
|
||||
break
|
||||
}
|
||||
while (a)
|
||||
return 1
|
||||
}
|
||||
|
||||
fun t5() : Int {
|
||||
do {
|
||||
return 1
|
||||
2
|
||||
}
|
||||
while (1 > 2)
|
||||
return 1
|
||||
}
|
||||
|
||||
fun t6() : Int {
|
||||
while (1 > 2) {
|
||||
return 1
|
||||
2
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
fun t6break() : Int {
|
||||
while (1 > 2) {
|
||||
break
|
||||
2
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
fun t7(b : Int) : Int {
|
||||
for (i in 1..b) {
|
||||
return 1
|
||||
2
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
fun t7break(b : Int) : Int {
|
||||
for (i in 1..b) {
|
||||
return 1
|
||||
2
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
fun t7() : Int {
|
||||
try {
|
||||
return 1
|
||||
2
|
||||
}
|
||||
catch (e : Any) {
|
||||
2
|
||||
}
|
||||
return 1 // this is OK, like in Java
|
||||
}
|
||||
|
||||
fun t8() : Int {
|
||||
try {
|
||||
return 1
|
||||
2
|
||||
}
|
||||
catch (e : Any) {
|
||||
return 1
|
||||
2
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
fun blockAndAndMismatch() : Boolean {
|
||||
(return true) || (return false)
|
||||
return true
|
||||
}
|
||||
|
||||
fun tf() : Int {
|
||||
try {return 1} finally{return 1}
|
||||
return 1
|
||||
}
|
||||
|
||||
fun failtest(a : Int) : Int {
|
||||
if (fail() || true) {
|
||||
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
fun foo(a : Nothing) : Unit {
|
||||
1
|
||||
a
|
||||
2
|
||||
}
|
||||
|
||||
fun fail() : Nothing {
|
||||
throw java.lang.<!UNRESOLVED_REFERENCE!>RuntimeException<!>()
|
||||
}
|
||||
|
||||
fun nullIsNotNothing() : Unit {
|
||||
val x : Int? = 1
|
||||
if (x != null) {
|
||||
return
|
||||
}
|
||||
fail()
|
||||
}
|
||||
|
||||
fun returnInWhile(a: Int) {
|
||||
do {return}
|
||||
while (1 > a)
|
||||
}
|
||||
compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeFromDifferentSources.fir.kt
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
package c
|
||||
|
||||
fun test1() {
|
||||
val r: Nothing = null!!
|
||||
}
|
||||
|
||||
fun test2(a: A) {
|
||||
a + a
|
||||
bar()
|
||||
}
|
||||
|
||||
fun test3() {
|
||||
null!!
|
||||
bar()
|
||||
}
|
||||
|
||||
fun throwNPE(): Nothing = null!!
|
||||
|
||||
class A {
|
||||
operator fun plus(a: A): Nothing = throw Exception()
|
||||
}
|
||||
|
||||
fun bar() {}
|
||||
Vendored
+40
@@ -0,0 +1,40 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun testArrayAccess1(array: Array<Any>) {
|
||||
array[todo()]
|
||||
}
|
||||
|
||||
fun testArrayAccess2() {
|
||||
operator fun Nothing.get(i: Int, s: String) {}
|
||||
todo()[1, ""]
|
||||
}
|
||||
|
||||
fun testAraryAccess3() {
|
||||
operator fun Nothing.get(n: Nothing) {}
|
||||
todo()[todo()]
|
||||
}
|
||||
|
||||
fun testArrayAssignment1(array: Array<Any>) {
|
||||
array[todo()] = 11
|
||||
}
|
||||
|
||||
fun testArrayAssignment2(array: Array<Any>) {
|
||||
array[1] = todo()
|
||||
}
|
||||
|
||||
fun testArrayAssignment3(n: Nothing) {
|
||||
operator fun Nothing.set(i: Int, j: Int) {}
|
||||
n[1] = 2
|
||||
}
|
||||
|
||||
fun testArrayAssignment4(n: Nothing) {
|
||||
operator fun Nothing.set(i: Int, a: Any) {}
|
||||
n[1] = todo()
|
||||
}
|
||||
|
||||
fun testArrayPlusAssign(array: Array<Any>) {
|
||||
operator fun Any.plusAssign(a: Any) {}
|
||||
array[1] += todo()
|
||||
}
|
||||
|
||||
fun todo(): Nothing = throw Exception()
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
fun testAssignment() {
|
||||
var a = 1
|
||||
a = todo()
|
||||
}
|
||||
|
||||
fun testVariableDeclaration() {
|
||||
val a = todo()
|
||||
}
|
||||
|
||||
fun testPlusAssign() {
|
||||
operator fun Int.plusAssign(i: Int) {}
|
||||
|
||||
var a = 1
|
||||
a += todo()
|
||||
}
|
||||
|
||||
|
||||
fun todo(): Nothing = throw Exception()
|
||||
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
fun testBinary1() {
|
||||
operator fun Int.times(s: String) {}
|
||||
|
||||
todo() * ""
|
||||
}
|
||||
fun testBinary2() {
|
||||
"1" + todo()
|
||||
}
|
||||
|
||||
fun testElvis1() {
|
||||
todo() ?: ""
|
||||
}
|
||||
|
||||
fun testElvis2(s: String?) {
|
||||
s ?: todo()
|
||||
|
||||
bar()
|
||||
}
|
||||
|
||||
fun testAnd1(b: Boolean) {
|
||||
b && todo()
|
||||
|
||||
bar()
|
||||
}
|
||||
|
||||
fun testAnd2(b: Boolean) {
|
||||
todo() && b
|
||||
}
|
||||
|
||||
fun returnInBinary1(): Boolean {
|
||||
(return true) && (return false)
|
||||
}
|
||||
|
||||
fun returnInBinary2(): Boolean {
|
||||
(return true) || (return false)
|
||||
}
|
||||
|
||||
fun todo(): Nothing = throw Exception()
|
||||
fun bar() {}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun testArgumentInCall() {
|
||||
fun bar(i: Int, s: String, x: Any) {}
|
||||
|
||||
bar(1, todo(), "")
|
||||
}
|
||||
|
||||
fun testArgumentInVariableAsFunctionCall(f: (Any) -> Unit) {
|
||||
f(todo())
|
||||
}
|
||||
|
||||
fun todo(): Nothing = throw Exception()
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun unreachable0() {
|
||||
return
|
||||
return todo()
|
||||
}
|
||||
|
||||
fun unreachable2() {
|
||||
return
|
||||
val a = todo()
|
||||
}
|
||||
|
||||
fun unreachable3() {
|
||||
return
|
||||
bar(todo())
|
||||
}
|
||||
|
||||
fun unreachable4(array: Array<Any>) {
|
||||
return
|
||||
array[todo()]
|
||||
}
|
||||
|
||||
fun bar(a: Any) {}
|
||||
fun todo(): Nothing = throw Exception()
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fun testIf() {
|
||||
if (todo()) 1 else 2
|
||||
}
|
||||
|
||||
fun testIf1(b: Boolean) {
|
||||
if (b) todo() else 1
|
||||
|
||||
bar()
|
||||
}
|
||||
|
||||
fun todo(): Nothing = throw Exception()
|
||||
fun bar() {}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun testCompound() {
|
||||
operator fun Nothing.get(i: Int) {}
|
||||
todo()!![12]
|
||||
}
|
||||
|
||||
fun testCompound1() {
|
||||
operator fun Int.times(s: String): Array<String> = throw Exception()
|
||||
(todo() * "")[1]
|
||||
}
|
||||
|
||||
fun todo(): Nothing = throw Exception()
|
||||
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun testObject() {
|
||||
object : Foo(todo()) {
|
||||
fun foo() = 1
|
||||
}
|
||||
}
|
||||
|
||||
fun testObjectExpression() {
|
||||
val a = object : Foo(todo()) {
|
||||
fun foo() = 1
|
||||
}
|
||||
}
|
||||
|
||||
fun testObjectExpression1() {
|
||||
fun bar(i: Int, x: Any) {}
|
||||
|
||||
bar(1, object : Foo(todo()) {
|
||||
fun foo() = 1
|
||||
})
|
||||
}
|
||||
|
||||
fun testClassDeclaration() {
|
||||
class C : Foo(todo()) {}
|
||||
|
||||
bar()
|
||||
}
|
||||
|
||||
fun testFunctionDefaultArgument() {
|
||||
fun foo(x: Int = todo()) { bar() }
|
||||
}
|
||||
|
||||
open class Foo(i: Int) {}
|
||||
|
||||
fun todo(): Nothing = throw Exception()
|
||||
fun bar() {}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
fun testFor() {
|
||||
operator fun Nothing.iterator() = (0..1).iterator()
|
||||
|
||||
for (i in todo()) {}
|
||||
}
|
||||
|
||||
fun testWhile() {
|
||||
while (todo()) {
|
||||
}
|
||||
}
|
||||
|
||||
fun testDoWhile() {
|
||||
do {
|
||||
|
||||
} while(todo())
|
||||
|
||||
bar()
|
||||
}
|
||||
|
||||
fun todo(): Nothing = throw Exception()
|
||||
fun bar() {}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun testReturn() {
|
||||
return todo()
|
||||
}
|
||||
|
||||
fun todo(): Nothing = throw Exception()
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
fun testPrefix() {
|
||||
operator fun Any.not() {}
|
||||
!todo()
|
||||
}
|
||||
|
||||
fun testPostfixWithCall(n: Nothing) {
|
||||
operator fun Nothing.inc(): Nothing = this
|
||||
n++
|
||||
}
|
||||
|
||||
fun testPostfixSpecial() {
|
||||
todo()!!
|
||||
}
|
||||
|
||||
fun todo(): Nothing = throw Exception()
|
||||
Vendored
+55
@@ -0,0 +1,55 @@
|
||||
fun foo(a: Any) {}
|
||||
fun bar(a: Any, b: Any) {}
|
||||
|
||||
fun test(arr: Array<Int>) {
|
||||
while (true) {
|
||||
foo(break)
|
||||
}
|
||||
|
||||
|
||||
while (true) {
|
||||
bar(arr, break)
|
||||
}
|
||||
|
||||
while (true) {
|
||||
arr[break]
|
||||
}
|
||||
|
||||
while (true) {
|
||||
arr[1] = break
|
||||
}
|
||||
|
||||
while (true) {
|
||||
break
|
||||
foo(1)
|
||||
}
|
||||
|
||||
while (true) {
|
||||
var x = 1
|
||||
break
|
||||
x = 2
|
||||
}
|
||||
|
||||
while (true) {
|
||||
var x = 1
|
||||
x = break
|
||||
}
|
||||
|
||||
// TODO: bug, should be fixed in CFA
|
||||
while (true) {
|
||||
if (1 > 2 && break && 2 > 3) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: bug, should be fixed in CFA
|
||||
while (true) {
|
||||
if (1 > 2 || break || 2 > 3) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
break ?: null
|
||||
}
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
fun main() {
|
||||
"".run {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun <T> T.run(f: (T) -> Unit): Unit = f(this)
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
//KT-2585 Code in try-finally is incorrectly marked as unreachable
|
||||
|
||||
fun foo(x: String): String {
|
||||
try {
|
||||
throw RuntimeException()
|
||||
} finally {
|
||||
try {
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
return x // <- Wrong UNREACHABLE_CODE
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
//KT-2585 Code in try-finally is incorrectly marked as unreachable
|
||||
|
||||
fun foo() {
|
||||
try {
|
||||
throw RuntimeException()
|
||||
} catch (e: Exception) {
|
||||
return // <- Wrong UNREACHABLE_CODE
|
||||
} finally {
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
try {
|
||||
throw RuntimeException()
|
||||
} catch (e: Exception) {
|
||||
return // <- Wrong UNREACHABLE_CODE
|
||||
} finally {
|
||||
while (cond());
|
||||
}
|
||||
}
|
||||
|
||||
fun cond() = true
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
//KT-2585 Code in try-finally is incorrectly marked as unreachable
|
||||
|
||||
fun foo(x: String): String {
|
||||
try {
|
||||
throw RuntimeException() //should be marked as unreachable, but is not
|
||||
} finally {
|
||||
throw NullPointerException()
|
||||
}
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
//KT-3162 More precise try-finally error marking
|
||||
|
||||
fun foo(x: String) : String {
|
||||
val a = try {
|
||||
x
|
||||
} finally {
|
||||
try {
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
return x
|
||||
}
|
||||
}
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
//KT-5200 Mark unreachable code in lambdas
|
||||
|
||||
fun test1(): String {
|
||||
doCall local@ {
|
||||
throw NullPointerException()
|
||||
"b3" //unmarked
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun test2(nonLocal: String, b: Boolean): String {
|
||||
doCall local@ {
|
||||
if (b) {
|
||||
return@local "b1"
|
||||
} else {
|
||||
return@local "b2"
|
||||
}
|
||||
"b3" //unmarked
|
||||
}
|
||||
|
||||
return nonLocal
|
||||
}
|
||||
|
||||
inline fun doCall(block: ()-> String) = block()
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
|
||||
inline fun myRun(b: () -> Unit) = b()
|
||||
|
||||
fun foo() {
|
||||
var a: Int
|
||||
return
|
||||
|
||||
myRun {
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user