FIR: Adjust testData for spec tests: expressions

This commit is contained in:
Denis Zharkov
2020-04-15 13:12:50 +03:00
parent 06bae1e52f
commit ee75347bb0
29 changed files with 1524 additions and 0 deletions
@@ -0,0 +1,75 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, try-expression -> paragraph 1 -> sentence 3
* RELEVANT PLACES: expressions, try-expression -> paragraph 1 -> sentence 2
* NUMBER: 1
* DESCRIPTION: try-expression has to start with a try body and continue with zero ore more catch blocks
*/
fun throwException(): Nothing = throw Exception()
class ExcA() : Exception()
class ExcB() : Exception()
// TESTCASE NUMBER: 1
fun case1() {
try <!SYNTAX!><!>val a = ""
<!UNRESOLVED_REFERENCE!>catch<!>(<!UNRESOLVED_REFERENCE!>e<!><!SYNTAX!>: Exception<!>) {}
}<!SYNTAX!><!>
// TESTCASE NUMBER: 2
fun case2() {
try {
val a = ""
} catch (e: Exception)<!SYNTAX!><!>
}
// TESTCASE NUMBER: 3
fun case3() {
try {
val a = ""
throwException()
} catch (e: java.lang.IllegalArgumentException) {
} catch (e: ExcB)<!SYNTAX!><!>
}
// TESTCASE NUMBER: 4
fun case4() {
try {
throwException()
} catch (<!SYNTAX!><!>) {
}
}
// TESTCASE NUMBER: 5
fun case5() {
try {
throwException()
} catch (e: ExcA, <!SYNTAX!>e2<!><!SYNTAX!><!> <!SYNTAX!>: ExcB)<!>
{}
}
// TESTCASE NUMBER: 6
fun case6() {
try {
val a = ""
throwException()
} catch (e: java.lang.IllegalArgumentException) {
} catch (e: ExcA)<!SYNTAX!><!>
catch (e: ExcB) {
}
}
@@ -0,0 +1,45 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, try-expression -> paragraph 1 -> sentence 4
* RELEVANT PLACES: expressions, try-expression -> paragraph 1 -> sentence 2
* NUMBER: 1
* DESCRIPTION: try-expression has to start with a try body, catch blocks and finally block
*/
fun throwException(): Nothing = throw Exception()
class ExcA() : Exception()
class ExcB() : Exception()
// TESTCASE NUMBER: 1
fun case1() {
try {
throwException()
} catch (e: ExcA) {
} finally {
} <!UNRESOLVED_REFERENCE!>catch<!> (<!UNRESOLVED_REFERENCE!>e<!><!SYNTAX!><!SYNTAX!><!>: ExcB)<!> {
}
}
// TESTCASE NUMBER: 2
fun case2() {
try {
throwException()
} catch (e: ExcB) {
} finally
<!SYNTAX!><!>}<!SYNTAX!><!>
// TESTCASE NUMBER: 3
fun case3() {
try {
throwException()
} finally
<!SYNTAX!><!>}<!SYNTAX!><!>
@@ -0,0 +1,36 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE:expressions, try-expression -> paragraph 1 -> sentence 1
* RELEVANT PLACES: expressions, try-expression -> paragraph 1 -> sentence 2
* expressions, try-expression -> paragraph 1 -> sentence 5
* NUMBER: 1
* DESCRIPTION: try-expression has to start with a try body
*/
fun throwException(): Nothing = throw Exception()
// TESTCASE NUMBER: 1
fun case1() {
try {
throwException()
}finally {
"a"
}
}
// TESTCASE NUMBER: 2
fun case2() {
try {
val a = throwException()
}catch (e: Exception) {
"a"
}
}
@@ -0,0 +1,25 @@
// !LANGUAGE: +NewInference
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, try-expression -> paragraph 2 -> sentence 2
* RELEVANT PLACES: expressions, try-expression -> paragraph 2 -> sentence 1
* NUMBER: 1
* DESCRIPTION: catch block is evaluated immediately after the exception is thrown and the exception itself is passed inside the catch block as the corresponding parameter.
*/
// TESTCASE NUMBER: 1
fun case1() {
var flag = false
try {
throw Exception()
flag = true
} catch (e: Exception) {
assert(!flag)
}
}
@@ -0,0 +1,27 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, try-expression -> paragraph 5 -> sentence 1
* RELEVANT PLACES: expressions, try-expression -> paragraph 4 -> sentence 1
* NUMBER: 1
* DESCRIPTION: If no exception is thrown during the evaluation of the try body, no catch blocks are executed, the finally block is evaluated after the try body, and the program execution continues as normal.
*/
// TESTCASE NUMBER: 1
fun case1(): String {
var flag = false
try {
flag = true
} catch (e: Exception) {
return "foo"
} finally {
return "FINALLY"
}
return "return"
}
@@ -0,0 +1,31 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, try-expression -> paragraph 5 -> sentence 2
* RELEVANT PLACES: expressions, try-expression -> paragraph 4 -> sentence 1
* NUMBER: 1
* DESCRIPTION: If an exception was thrown, but no catch block matched its type, the finally block is evaluated before propagating the exception up the call stack.
*/
/*
* TESTCASE NUMBER: 1
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-23680
*/
fun case1(): Int {
var a = 1
try {
throw Exception() //invalid UNREACHABLE_CODE diagnostic
} catch (e: Exception) {
a = 5
return++a
} finally {
return a
}
return 0
}
@@ -0,0 +1,66 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_VARIABLE -UNUSED_PARAMETER -FINAL_UPPER_BOUND
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-296
* PLACE: expressions, try-expression -> paragraph 8 -> sentence 1
* RELEVANT PLACES: expressions, try-expression -> paragraph 9 -> sentence 1
* NUMBER: 1
* DESCRIPTION: The type of the try-expression is the least upper bound of the types of the last expressions of the try body and the last expressions of all the catch blocks
*/
fun throwExceptionA(b: Boolean) = run { if (b) throw ExcA() }
open class A<T>(var data: T) {
fun foo(d: A<T>) {}
}
class B<T>(data: T) : A<T>(data)
// TESTCASE NUMBER: 1
fun case1() {
val tryVal: B<String> =
try {
throwExceptionA(false)
A("")
} catch (e: Exception) {
B("")
}
}
// TESTCASE NUMBER: 2
fun case2() {
val tryVal: A<String> =
try {
throwExceptionA(false)
A("")
} catch (e: Exception) {
null
}
}
/*
* TESTCASE NUMBER: 3
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-35494
*/
fun case3() {
val tryVal: A<Int> =
try {
throwExceptionA(false)
A(2)
} catch (e: ExcA) {
A(null) //diag duplication
} catch (e: ExcB) {
B(null) //diag duplication
}
}
class ExcA() : Exception()
class ExcB() : Exception()