[Spec tests] Review fix tests for try-expression and if-expression

This commit is contained in:
anastasiia.spaseeva
2019-12-16 17:19:52 +03:00
parent e865327386
commit bd979a12de
21 changed files with 765 additions and 35 deletions
@@ -1,5 +1,5 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// !DIAGNOSTICS: -IMPLICIT_CAST_TO_ANY -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// SKIP_TXT
/*
@@ -0,0 +1,32 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -IMPLICIT_CAST_TO_ANY -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: control--and-data-flow-analysis, control-flow-graph, expressions-1, conditional-expressions -> paragraph 1 -> sentence 1
* NUMBER: 2
* DESCRIPTION: check if-expressions must have both branches.
*/
// TESTCASE NUMBER: 1
fun case1() {
val b = true
val c = true
val a = if (b) {
"first true"
} else <!INVALID_IF_AS_EXPRESSION!>if<!> (c) {
"else if true"
}
}
// TESTCASE NUMBER: 2
fun case2() {
var b = true
val c = true
val a = if (b) 1 else <!INVALID_IF_AS_EXPRESSION!>if<!> (c) 2 else ;
}
@@ -0,0 +1,83 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNREACHABLE_CODE -IMPLICIT_CAST_TO_ANY -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: control--and-data-flow-analysis, control-flow-graph, expressions-1, conditional-expressions -> paragraph 1 -> sentence 1
* NUMBER: 3
* DESCRIPTION: check if-expressions must have both branches. (attempt to pass Nothing to if-condition without 'else' key word)
*/
fun throwExc(b: Boolean): Boolean {
if (b) throw Exception()
else return false
}
// TESTCASE NUMBER: 1
fun case1() {
val x1 = <!INVALID_IF_AS_EXPRESSION!>if<!> (throwExc(false)) true
}
// TESTCASE NUMBER: 3
fun case3() {
val x1 = <!INVALID_IF_AS_EXPRESSION!>if<!> (throwExc(true)) true
}
/*
* TESTCASE NUMBER: 4
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-35510
*/
fun case4() {
val x1 = if (throw Exception()) true
val x2 = if (TODO()) true
val x0 = if (false) true else if (throw Exception()) ;
}
// TESTCASE NUMBER: 5
fun case5() {
var flag: Boolean? = null
val x1 = <!INVALID_IF_AS_EXPRESSION!>if<!> (flag ?: throw Exception()) true
}
/*
* TESTCASE NUMBER: 6
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-35510
*/
fun case6() {
val k1 = if(throw Exception());
}
/*
* TESTCASE NUMBER: 7
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-35510
*/
fun case7(nothing: Nothing) {
val k1 = if(throw Exception())
<!SYNTAX!><!>}
/*
* TESTCASE NUMBER: 8
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-35510
*/
fun case8(nothing: Nothing) {
val x1 = if (nothing) true
}
/*
* TESTCASE NUMBER: 9
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-35510
*/fun case9() {
val k1 = if(throw Exception())
<!SYNTAX!><!>}
@@ -0,0 +1,48 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNREACHABLE_CODE -IMPLICIT_CAST_TO_ANY -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: control--and-data-flow-analysis, control-flow-graph, expressions-1, conditional-expressions -> paragraph 1 -> sentence 1
* NUMBER: 4
* DESCRIPTION: check if-expressions must have both branches. (attempt to pass Nothing to if-condition with 'else' key word)
*/
// TESTCASE NUMBER: 1
fun case1() {
val y0else = <!INVALID_IF_AS_EXPRESSION!>if<!> (false) true else ;
}
/*
* TESTCASE NUMBER: 2
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-35510
*/
fun case2(nothing: Nothing) {
val n1else = if (nothing) true else;
}
/*
* TESTCASE NUMBER: 3
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-35510
*/
fun case3(nothing: Nothing) {
val n1else = if (nothing) true else
<!SYNTAX!><!>}
// TESTCASE NUMBER: 4
fun case4(nothing: Nothing) {
val x = <!INVALID_IF_AS_EXPRESSION!>if<!> (false) else if (nothing) { "foo"} else
<!SYNTAX!><!>}
// TESTCASE NUMBER: 5
fun case5(nothing: Nothing) {
val x = <!INVALID_IF_AS_EXPRESSION!>if<!> (false) else if (nothing) { "foo"} else ;
}
@@ -0,0 +1,34 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -IMPLICIT_CAST_TO_ANY -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION -DEBUG_INFO_SMARTCAST
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: control--and-data-flow-analysis, control-flow-graph, expressions-1, conditional-expressions -> paragraph 1 -> sentence 1
* NUMBER: 2
* DESCRIPTION: check if-expressions must have both branches.
* HELPERS: checkType
*/
// TESTCASE NUMBER: 1
fun case1() {
val b = true
val c = true
val a = if (b) {
"first true"
} else if (c) {
"else if true"
} else {}
}
// TESTCASE NUMBER: 2
fun case2() {
var b = true
val c = true
val a = if (b) 1 else if (c) 2 else Unit;
}
@@ -10,6 +10,24 @@
}
],
"1": [
{
"specVersion": "0.1-213",
"casesNumber": 2,
"description": "check if-expressions must have both branches.",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-213",
"casesNumber": 8,
"description": "check if-expressions must have both branches. (attempt to pass Nothing to if-condition without \u0027else\u0027 key word)",
"unexpectedBehaviour": true
},
{
"specVersion": "0.1-213",
"casesNumber": 5,
"description": "check if-expressions must have both branches. (attempt to pass Nothing to if-condition with \u0027else\u0027 key word)",
"unexpectedBehaviour": true
},
{
"specVersion": "0.1-213",
"casesNumber": 2,
@@ -28,6 +46,12 @@
}
],
"1": [
{
"specVersion": "0.1-213",
"casesNumber": 2,
"description": "check if-expressions must have both branches.",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-213",
"casesNumber": 3,
@@ -0,0 +1,52 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// SKIP_TXT
// FULL_JDK
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, conditional-expression -> paragraph 6 -> sentence 1
* NUMBER: 1
* DESCRIPTION: The type of the condition expression must be a subtype of kotlin.Boolean
* HELPERS: checkType
*/
// MODULE: libModule
// FILE: libModule/JavaContainer.java
package libModule;
public class JavaContainer {
public static boolean ab;
public static final Boolean aB;
public static Object aO = false;
}
// MODULE: mainModule(libModule)
// FILE: KotlinClass.kt
package mainModule
import libModule.*
import checkSubtype
/*
* TESTCASE NUMBER: 1
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-35517
*/
fun case1() {
val a: Any = true
if (<!TYPE_MISMATCH, TYPE_MISMATCH!>a<!>) { "true" } else "false"
checkSubtype<Boolean>(<!TYPE_MISMATCH!>a<!>)
}
/*
* TESTCASE NUMBER: 2
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-35517
*/
fun case2() {
val a = JavaContainer.aO
if (<!TYPE_MISMATCH, TYPE_MISMATCH!>a<!>) { "true" } else "false"
checkSubtype<Boolean>(<!TYPE_MISMATCH!>a<!>)
}
@@ -0,0 +1,58 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNREACHABLE_CODE -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
// SKIP_TXT
// FULL_JDK
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, conditional-expression -> paragraph 6 -> sentence 1
* NUMBER: 1
* DESCRIPTION: The type of the condition expression must be a subtype of kotlin.Boolean
* HELPERS: checkType
*/
// MODULE: libModule
// FILE: libModule/JavaContainer.java
package libModule;
public class JavaContainer {
public static boolean ab;
public static Boolean aB;
public static final Object aO = false;
}
// MODULE: mainModule(libModule)
// FILE: KotlinClass.kt
package mainModule
import libModule.*
import checkSubtype
// TESTCASE NUMBER: 1
fun case1() {
val a = JavaContainer.ab
if (a) { "true" } else "false"
checkSubtype<Boolean>(a)
checkSubtype<Boolean>(false)
}
// TESTCASE NUMBER: 2
fun case2() {
val a = JavaContainer.aB
if (a) { "true" } else "false"
checkSubtype<Boolean>(a)
}
// TESTCASE NUMBER: 3
fun case3() {
val a = JavaContainer.aO as Boolean
if (a) { "true" } else "false"
checkSubtype<Boolean>(a)
}
// TESTCASE NUMBER: 4
fun case4(a: Nothing) {
checkSubtype<Boolean>(a)
if (a) { "true" } else "false"
}
@@ -0,0 +1,92 @@
{
"6": {
"neg": {
"1": [
{
"specVersion": "0.1-218",
"casesNumber": 2,
"description": "The type of the condition expression must be a subtype of kotlin.Boolean",
"unexpectedBehaviour": true
}
]
},
"pos": {
"1": [
{
"specVersion": "0.1-218",
"casesNumber": 4,
"description": "The type of the condition expression must be a subtype of kotlin.Boolean",
"unexpectedBehaviour": false
}
]
}
},
"4": {
"pos": {
"1": [
{
"specVersion": "0.1-152",
"casesNumber": 0,
"description": "Kt9929",
"path": "compiler/testData/diagnostics/tests/when/kt9929.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-152",
"casesNumber": 0,
"description": "Kt10811",
"path": "compiler/testData/diagnostics/tests/when/kt10811.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-152",
"casesNumber": 0,
"description": "Kt9972",
"path": "compiler/testData/diagnostics/tests/when/kt9972.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-152",
"casesNumber": 0,
"description": "Kt10809",
"path": "compiler/testData/diagnostics/tests/when/kt10809.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-152",
"casesNumber": 0,
"description": "Kt10439",
"path": "compiler/testData/diagnostics/tests/when/kt10439.kt",
"unexpectedBehaviour": false
}
]
}
},
"5": {
"pos": {
"1": [
{
"specVersion": "0.1-152",
"casesNumber": 0,
"description": "Kt9929",
"path": "compiler/testData/diagnostics/tests/when/kt9929.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-152",
"casesNumber": 0,
"description": "Kt9972",
"path": "compiler/testData/diagnostics/tests/when/kt9972.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-152",
"casesNumber": 0,
"description": "Kt10439",
"path": "compiler/testData/diagnostics/tests/when/kt10439.kt",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -145,9 +145,9 @@
"1": [
{
"specVersion": "0.1-218",
"casesNumber": 2,
"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
"unexpectedBehaviour": true
}
]
},
@@ -162,15 +162,15 @@
]
}
},
"4": {
"9": {
"neg": {
"1": [
{
"specVersion": "0.1-218",
"casesNumber": 2,
"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/neg/1.1.kt",
"unexpectedBehaviour": false
"unexpectedBehaviour": true
}
]
},
@@ -182,20 +182,6 @@
"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
}
]
}
@@ -240,5 +226,25 @@
}
]
}
},
"4": {
"pos": {
"1": [
{
"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
}
]
}
}
}