[Spec tests] Add spec tests for kotlin.Nothing, kotlin.Unit, reference equality and cast expressions
This commit is contained in:
+69
@@ -0,0 +1,69 @@
|
||||
// !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-213
|
||||
* PLACE: expressions, built-in-types-and-their-semantics, kotlin.nothing-1 -> paragraph 1 -> sentence 1
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: check the type of jump expressions is Nothing and code placed on the left side of expression will never be executed
|
||||
*/
|
||||
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
|
||||
fun case1() {
|
||||
var name: Any? = null
|
||||
val men = arrayListOf(Person("Phill"), Person(), Person("Bob"))
|
||||
for (k in men) {
|
||||
k.name
|
||||
loop@ for (i in men) {
|
||||
i.name
|
||||
<!UNREACHABLE_CODE!>val valeua : Int =<!> break@loop
|
||||
<!UNREACHABLE_CODE!>i.name<!>
|
||||
}
|
||||
k.name
|
||||
val s = k.name ?: break
|
||||
k.name
|
||||
}
|
||||
val a = 1
|
||||
}
|
||||
|
||||
class Person(var name: String? = null) {}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
|
||||
fun case2() {
|
||||
var name: Any? = null
|
||||
val men = arrayListOf(Person("Phill"), Person(), Person("Bob"))
|
||||
for (k in men) {
|
||||
loop@ for (i in men) {
|
||||
i.name
|
||||
<!UNREACHABLE_CODE!>val val1 =<!> continue@loop
|
||||
<!UNREACHABLE_CODE!>val1<!>
|
||||
<!UNREACHABLE_CODE!>i.name<!>
|
||||
}
|
||||
val s = k.name ?: continue
|
||||
k.name
|
||||
}
|
||||
val a = 1
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
|
||||
fun case3() {
|
||||
listOf(1, 2, 3, 4, 5).forEach { x ->
|
||||
val k = x
|
||||
|
||||
listOf(1, 2, 3, 4, 5).forEach lit@{
|
||||
it
|
||||
return@lit
|
||||
<!UNREACHABLE_CODE!>print(it)<!>
|
||||
}
|
||||
val y = x
|
||||
if (x == 3) return
|
||||
}
|
||||
val a = 1
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"1": {
|
||||
"pos": {
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-213",
|
||||
"casesNumber": 3,
|
||||
"description": "check the type of jump expressions is Nothing and code placed on the left side of expression will never be executed",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+57
@@ -0,0 +1,57 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION -UNREACHABLE_CODE
|
||||
// SKIP_TXT
|
||||
|
||||
/*
|
||||
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-213
|
||||
* PLACE: expressions, jump-expressions -> paragraph 2 -> sentence 1
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: check he type of jump expressions is the kotlin.Nothing
|
||||
*/
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
|
||||
fun case1() {
|
||||
var name: Any? = null
|
||||
val men = arrayListOf(Person("Phill"), Person(), Person("Bob"))
|
||||
for (k in men) {
|
||||
k.name
|
||||
loop@ for (i in men) {
|
||||
val val1: Int = <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>break@loop<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>val1<!>
|
||||
}
|
||||
val s = k.name ?: <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>break<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>s<!>
|
||||
}
|
||||
}
|
||||
|
||||
class Person(var name: String? = null) {}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
|
||||
fun case2() {
|
||||
var name: Any? = null
|
||||
val men = arrayListOf(Person("Phill"), Person(), Person("Bob"))
|
||||
for (k in men) {
|
||||
loop@ for (i in men) {
|
||||
val val1 = <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>continue@loop<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>val1<!>
|
||||
}
|
||||
val s = k.name ?: <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>continue<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>s<!>
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
|
||||
fun case3() {
|
||||
listOf(1, 2, 3, 4, 5).forEach { x ->
|
||||
listOf(1, 2, 3, 4, 5).forEach lit@{
|
||||
val s = <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>return@lit<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>s<!>
|
||||
}
|
||||
if (x == 3) <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>return<!>
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"2": {
|
||||
"pos": {
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-213",
|
||||
"casesNumber": 3,
|
||||
"description": "check he type of jump expressions is the kotlin.Nothing",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-1
@@ -1,4 +1,5 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION -UNREACHABLE_CODE
|
||||
// SKIP_TXT
|
||||
|
||||
/*
|
||||
@@ -16,5 +17,16 @@
|
||||
class Case1(val nothing: Nothing)
|
||||
|
||||
fun case1() {
|
||||
val res = Case1(Nothing())
|
||||
val res = Case1(<!INVISIBLE_MEMBER!>Nothing<!>())
|
||||
}
|
||||
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
class Case2 {
|
||||
var data: String? = null
|
||||
}
|
||||
|
||||
fun case2(c: Case2) {
|
||||
val testValue = c.data ?: throw IllegalArgumentException("data required")
|
||||
testValue checkType { <!NONE_APPLICABLE!>check<!><Nothing>() }
|
||||
}
|
||||
+13
-7
@@ -1,4 +1,6 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION -UNREACHABLE_CODE
|
||||
|
||||
// SKIP_TXT
|
||||
|
||||
/*
|
||||
@@ -8,26 +10,30 @@
|
||||
* PLACE: type-system, type-kinds, built-in-types, kotlin.nothing -> paragraph 1 -> sentence 1
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: Check of Nothing type is a subtype of any types
|
||||
* HELPERS: checkType
|
||||
* HELPERS: checkType, functions
|
||||
*/
|
||||
|
||||
|
||||
|
||||
class NothingWrapper() {
|
||||
val data: Nothing
|
||||
val data: Nothing = TODO()
|
||||
}
|
||||
|
||||
class CustomClass
|
||||
class CustomClass() {}
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
fun case1(wrapper: NothingWrapper) {
|
||||
fun case1() {
|
||||
val wrapper: NothingWrapper = NothingWrapper()
|
||||
checkSubtype<Any>(wrapper.data)
|
||||
checkSubtype<Any>(wrapper.data)
|
||||
|
||||
checkSubtype<Any>(wrapper.data)
|
||||
checkSubtype<Function<Nothing>>(wrapper.data)
|
||||
checkSubtype<Int>(wrapper.data)
|
||||
checkSubtype<Short>(wrapper.data)
|
||||
checkSubtype<Byte>(wrapper.data)
|
||||
checkSubtype<Long>(wrapper.data)
|
||||
checkSubtype<kotlin.Array>(wrapper.data)
|
||||
checkSubtype<kotlin.Array<Any>>(wrapper.data)
|
||||
checkSubtype<CustomClass>(wrapper.data)
|
||||
}
|
||||
|
||||
@@ -35,10 +41,10 @@ fun case1(wrapper: NothingWrapper) {
|
||||
fun case2(wrapper: NothingWrapper) {
|
||||
checkSubtype<MutableList<out Nothing>>(wrapper.data)
|
||||
checkSubtype<MutableList<in String>>(wrapper.data)
|
||||
checkSubtype<MutableList<out CustomClass>>(wrapper.data)
|
||||
checkSubtype<MutableList<in CustomClass>>(wrapper.data)
|
||||
checkSubtype<MutableList<Any?>>(wrapper.data)
|
||||
|
||||
checkSubtype<String>(wrapper.data)
|
||||
|
||||
checkSubtype<in CustomClass>(wrapper.data)
|
||||
checkSubtype<out CustomClass>(wrapper.data)
|
||||
}
|
||||
+8
-17
@@ -1,4 +1,5 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION -UNREACHABLE_CODE
|
||||
// SKIP_TXT
|
||||
|
||||
/*
|
||||
@@ -8,11 +9,11 @@
|
||||
* PLACE: type-system, type-kinds, built-in-types, kotlin.nothing -> paragraph 1 -> sentence 2
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: Check of Nothing as a subtype of any type
|
||||
* HELPERS: checkType
|
||||
* HELPERS: checkType, functions
|
||||
*/
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
class Case1() {
|
||||
class Case1 {
|
||||
val data: Nothing = TODO()
|
||||
}
|
||||
|
||||
@@ -21,26 +22,16 @@ fun case1(c: Case1) {
|
||||
checkSubtype<Function<Nothing>>(c.data)
|
||||
}
|
||||
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
class Case2 {
|
||||
var data: String
|
||||
}
|
||||
|
||||
fun case2(c: Case2) {
|
||||
val testValue = c.data ?: throw IllegalArgumentException("data required")
|
||||
testValue checkType { check<Nothing>() }
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
class Case3 {
|
||||
val dataFunction = fail("fail msg")
|
||||
val dataFunction: Nothing = fail("fail msg")
|
||||
}
|
||||
|
||||
fun fail(msg: String): Nothing {
|
||||
throw new Exception (msg)
|
||||
throw Exception(msg)
|
||||
}
|
||||
|
||||
fun case3(c: Case3) {
|
||||
val testValue = c.dataFunction()
|
||||
checkType<Nothing>(testValue)
|
||||
fun case2(c: Case2) {
|
||||
c.dataFunction checkType { check<Nothing>() }
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@
|
||||
"2": [
|
||||
{
|
||||
"specVersion": "0.1-213",
|
||||
"casesNumber": 1,
|
||||
"casesNumber": 2,
|
||||
"description": "Check of Nothing type",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
"2": [
|
||||
{
|
||||
"specVersion": "0.1-213",
|
||||
"casesNumber": 3,
|
||||
"casesNumber": 2,
|
||||
"description": "Check of Nothing as a subtype of any type",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user