[Spec tests] Add tests for try-expression (paragraphs 1, 2, 5-9)
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
// !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 1
|
||||
* RELEVANT PLACES: expressions, try-expression -> paragraph 1 -> sentence 2
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: try-expression has to start with a try body
|
||||
*/
|
||||
fun throwException(): Nothing = throw Exception()
|
||||
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
|
||||
fun case1() {
|
||||
try <!SYNTAX!><!>throwException()
|
||||
}<!SYNTAX!><!>
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
|
||||
fun case2() {
|
||||
try <!SYNTAX!><!SYNTAX!><!>=<!> throwException()
|
||||
}<!SYNTAX!><!>
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
|
||||
fun case3() {
|
||||
try
|
||||
<!SYNTAX!><!>val a = ""
|
||||
}<!SYNTAX!><!>
|
||||
|
||||
+75
@@ -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)<!>
|
||||
<!UNUSED_LAMBDA_EXPRESSION!>{}<!>
|
||||
}
|
||||
|
||||
|
||||
// TESTCASE NUMBER: 6
|
||||
|
||||
fun case6() {
|
||||
try {
|
||||
val a = ""
|
||||
throwException()
|
||||
} catch (e: java.lang.IllegalArgumentException) {
|
||||
} catch (e: ExcA)<!SYNTAX!><!>
|
||||
catch (e: ExcB) {
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
// !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)<!> <!UNUSED_LAMBDA_EXPRESSION!>{
|
||||
}<!>
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
|
||||
fun case2() {
|
||||
try {
|
||||
throwException()
|
||||
} catch (e: ExcB) {
|
||||
} finally
|
||||
<!SYNTAX!><!>}<!SYNTAX!><!>
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
|
||||
fun case3() {
|
||||
try {
|
||||
throwException()
|
||||
} finally
|
||||
<!SYNTAX!><!>}<!SYNTAX!><!>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// !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 5
|
||||
* RELEVANT PLACES: expressions, try-expression -> paragraph 1 -> sentence 2
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: A valid try-expression must have at least one catch or finally block.
|
||||
*/
|
||||
|
||||
fun throwException(): Nothing = throw Exception()
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
|
||||
fun case1() {
|
||||
try {
|
||||
throwException()
|
||||
}<!SYNTAX!><!>
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
|
||||
fun case2() {
|
||||
try {
|
||||
val a = "foo"
|
||||
}<!SYNTAX!><!>
|
||||
}
|
||||
+36
@@ -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 {
|
||||
<!UNREACHABLE_CODE!>val a =<!> throwException()
|
||||
}catch (e: Exception) {
|
||||
"a"
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// !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 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()
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
|
||||
fun case1() {
|
||||
try {
|
||||
val a = ""
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
|
||||
fun case2() {
|
||||
try {
|
||||
val a = ""
|
||||
throwException()
|
||||
} catch (e: IllegalArgumentException) {
|
||||
} catch (e: ExcA) {
|
||||
} catch (e: ExcB) {
|
||||
}
|
||||
}
|
||||
|
||||
class ExcA() : Exception()
|
||||
class ExcB() : Exception()
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
// !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 3
|
||||
* RELEVANT PLACES: expressions, try-expression -> paragraph 1 -> sentence 2
|
||||
* NUMBER: 2
|
||||
* DESCRIPTION: catch is a soft keyword
|
||||
*/
|
||||
fun throwException(): Nothing = throw Exception()
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
class Case1 {
|
||||
fun catch(e: Exception) {}
|
||||
|
||||
fun case1() {
|
||||
catch(Exception())
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
class Case2 {
|
||||
class catch(e: Exception) {}
|
||||
|
||||
fun case2() {
|
||||
val c = catch(Exception())
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
class Case3 {
|
||||
fun catch() {}
|
||||
|
||||
fun case3() {
|
||||
catch()
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 4
|
||||
class Case4 {
|
||||
class catch() {}
|
||||
|
||||
fun case4() {
|
||||
val c = catch()
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 5
|
||||
|
||||
class Case5() {
|
||||
interface catch
|
||||
|
||||
fun case5(){
|
||||
val c = object :catch{}
|
||||
}
|
||||
}
|
||||
|
||||
+36
@@ -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 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) {
|
||||
} catch (e: ExcB) {
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
|
||||
fun case2() {
|
||||
try {
|
||||
throwException()
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
// !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 4
|
||||
* RELEVANT PLACES: expressions, try-expression -> paragraph 1 -> sentence 2
|
||||
* NUMBER: 2
|
||||
* DESCRIPTION: finally is a soft keyword
|
||||
*/
|
||||
fun throwException(): Nothing = throw Exception()
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
class Case1 {
|
||||
fun finally(e: Exception) {}
|
||||
|
||||
fun case1() {
|
||||
finally(Exception())
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
class Case2 {
|
||||
class finally(e: Exception) {}
|
||||
|
||||
fun case2() {
|
||||
val c = finally(java.lang.Exception())
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
class Case3 {
|
||||
fun finally() {}
|
||||
|
||||
fun case3() {
|
||||
finally()
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 4
|
||||
class Case4 {
|
||||
class finally() {}
|
||||
|
||||
fun case4() {
|
||||
val c = finally()
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 5
|
||||
|
||||
class Case5() {
|
||||
interface finally
|
||||
|
||||
fun case5(){
|
||||
val c = object :finally{}
|
||||
}
|
||||
}
|
||||
|
||||
+25
@@ -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()
|
||||
<!UNREACHABLE_CODE!>flag = true<!>
|
||||
} catch (e: Exception) {
|
||||
assert(!flag)
|
||||
}
|
||||
}
|
||||
+27
@@ -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) {
|
||||
<!UNREACHABLE_CODE!>return<!> "foo"
|
||||
} finally {
|
||||
return "FINALLY"
|
||||
}
|
||||
<!UNREACHABLE_CODE!>return "return"<!>
|
||||
}
|
||||
+31
@@ -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 {
|
||||
<!UNREACHABLE_CODE!>throw<!> Exception() //invalid UNREACHABLE_CODE diagnostic
|
||||
} catch (e: Exception) {
|
||||
a = 5
|
||||
<!UNREACHABLE_CODE!>return<!>++a
|
||||
} finally {
|
||||
return a
|
||||
}
|
||||
<!UNREACHABLE_CODE!>return 0<!>
|
||||
}
|
||||
+66
@@ -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-218
|
||||
* 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> =
|
||||
<!TYPE_MISMATCH, TYPE_MISMATCH!>try {
|
||||
throwExceptionA(false)
|
||||
A("")
|
||||
} catch (e: Exception) {
|
||||
B("")
|
||||
}<!>
|
||||
|
||||
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
|
||||
fun case2() {
|
||||
val tryVal: A<String> =
|
||||
<!TYPE_MISMATCH, TYPE_MISMATCH!>try {
|
||||
throwExceptionA(false)
|
||||
A("")
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}<!>
|
||||
}
|
||||
|
||||
/*
|
||||
* TESTCASE NUMBER: 3
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
* ISSUES: KT-35494
|
||||
*/
|
||||
fun case3() {
|
||||
val tryVal: A<Int> =
|
||||
<!TYPE_MISMATCH, TYPE_MISMATCH!>try {
|
||||
throwExceptionA(false)
|
||||
A(2)
|
||||
} catch (e: ExcA) {
|
||||
A(<!NULL_FOR_NONNULL_TYPE, NULL_FOR_NONNULL_TYPE!>null<!>) //diag duplication
|
||||
} catch (e: ExcB) {
|
||||
B(<!NULL_FOR_NONNULL_TYPE, NULL_FOR_NONNULL_TYPE!>null<!>) //diag duplication
|
||||
}<!>
|
||||
}
|
||||
|
||||
class ExcA() : Exception()
|
||||
class ExcB() : Exception()
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_EXPRESSION
|
||||
// SKIP_TXT
|
||||
|
||||
/*
|
||||
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-218
|
||||
* 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
|
||||
* HELPERS: checkType
|
||||
*/
|
||||
|
||||
fun throwExceptionA(b: Boolean) = run { if (b) throw ExcA() }
|
||||
|
||||
open class A<T>(var data: T) {}
|
||||
|
||||
class B<T>(data: T) : A<T>(data)
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
|
||||
fun case1() {
|
||||
val tryVal =
|
||||
try {
|
||||
throwExceptionA(false)
|
||||
A("")
|
||||
} catch (e: Exception) {
|
||||
B("")
|
||||
}
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("A<kotlin.String>")!>tryVal<!>
|
||||
tryVal checkType { check<A<kotlin.String>>() }
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
|
||||
fun case2() {
|
||||
val tryVal =
|
||||
try {
|
||||
throwExceptionA(false)
|
||||
A("")
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("A<kotlin.String>?")!>tryVal<!>
|
||||
tryVal checkType { check<A<kotlin.String>?>() }
|
||||
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
|
||||
fun case3() {
|
||||
val tryVal =
|
||||
try {
|
||||
throwExceptionA(false)
|
||||
A(2)
|
||||
} catch (e: ExcA) {
|
||||
A(0)
|
||||
} catch (e: ExcB) {
|
||||
B(null)
|
||||
}
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("A<out kotlin.Int?>")!>tryVal<!>
|
||||
tryVal checkType { check<A<out kotlin.Int?>>() }
|
||||
}
|
||||
|
||||
class ExcA() : Exception()
|
||||
class ExcB() : Exception()
|
||||
+244
@@ -0,0 +1,244 @@
|
||||
{
|
||||
"1": {
|
||||
"neg": {
|
||||
"3": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 6,
|
||||
"description": "try-expression has to start with a try body and continue with zero ore more catch blocks",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"2": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 6,
|
||||
"description": "try-expression has to start with a try body and continue with zero ore more catch blocks",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-1/neg/3.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 3,
|
||||
"description": "try-expression has to start with a try body, catch blocks and finally block",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-1/neg/4.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 2,
|
||||
"description": "A valid try-expression must have at least one catch or finally block.",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-1/neg/5.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 3,
|
||||
"description": "try-expression has to start with a try body",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-1/neg/1.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"4": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 3,
|
||||
"description": "try-expression has to start with a try body, catch blocks and finally block",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"5": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 2,
|
||||
"description": "A valid try-expression must have at least one catch or finally block.",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 3,
|
||||
"description": "try-expression has to start with a try body",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"pos": {
|
||||
"3": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 2,
|
||||
"description": "try-expression has to start with a try body and continue with zero ore more catch blocks",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 5,
|
||||
"description": "catch is a soft keyword",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"2": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 2,
|
||||
"description": "try-expression has to start with a try body and continue with zero ore more catch blocks",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-1/pos/3.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 2,
|
||||
"description": "try-expression has to start with a try body, catch blocks and finally block",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-1/pos/4.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 5,
|
||||
"description": "finally is a soft keyword",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-1/pos/4.2.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 5,
|
||||
"description": "catch is a soft keyword",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-1/pos/3.2.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 2,
|
||||
"description": "try-expression has to start with a try body",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-1/pos/1.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"4": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 2,
|
||||
"description": "try-expression has to start with a try body, catch blocks and finally block",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 5,
|
||||
"description": "finally is a soft keyword",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 2,
|
||||
"description": "try-expression has to start with a try body",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"8": {
|
||||
"neg": {
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 2,
|
||||
"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",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"pos": {
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 3,
|
||||
"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",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"4": {
|
||||
"neg": {
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 2,
|
||||
"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",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-8/neg/1.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"pos": {
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 3,
|
||||
"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",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-8/pos/1.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 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.",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-5/pos/2.1.kt",
|
||||
"unexpectedBehaviour": true
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 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.",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-5/pos/1.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"2": {
|
||||
"pos": {
|
||||
"2": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 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.",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
],
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 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.",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-2/pos/2.1.kt",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"5": {
|
||||
"pos": {
|
||||
"2": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 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.",
|
||||
"unexpectedBehaviour": true
|
||||
}
|
||||
],
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-218",
|
||||
"casesNumber": 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.",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user