[Spec tests] Add tests for subtyping rules for simple classifier type
This commit is contained in:
+118
@@ -0,0 +1,118 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNREACHABLE_CODE -UNUSED_PARAMETER
|
||||
// SKIP_TXT
|
||||
|
||||
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
class A
|
||||
|
||||
fun foo() : A = A()
|
||||
|
||||
interface AI{
|
||||
val ai0: String
|
||||
get() = ""
|
||||
}
|
||||
|
||||
val AI.ai1: Int
|
||||
get() = 1
|
||||
|
||||
|
||||
fun case1(a: A, ai: AI , nothing: Nothing) {
|
||||
|
||||
checkSubtype<Any>(a)
|
||||
checkSubtype<A>(nothing)
|
||||
|
||||
checkSubtype<Any>(foo())
|
||||
checkSubtype<A>(nothing)
|
||||
|
||||
checkSubtype<Any>(ai)
|
||||
checkSubtype<AI>(nothing)
|
||||
|
||||
checkSubtype<Any>(ai.ai0)
|
||||
checkSubtype<String>(nothing)
|
||||
|
||||
checkSubtype<Any>(ai.ai1)
|
||||
checkSubtype<Int>(nothing)
|
||||
|
||||
checkSubtype<Any>(nothing)
|
||||
checkSubtype<Nothing>(nothing)
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
fun case2( nothing: Nothing) {
|
||||
|
||||
checkSubtype<Any>("a")
|
||||
checkSubtype<String>(nothing)
|
||||
checkSubtype<CharSequence>(nothing)
|
||||
checkSubtype<CharSequence>("")
|
||||
|
||||
checkSubtype<Any>(1)
|
||||
checkSubtype<Int>(nothing)
|
||||
|
||||
checkSubtype<Any>(1.0)
|
||||
checkSubtype<Double>(nothing)
|
||||
|
||||
checkSubtype<Any>(true)
|
||||
checkSubtype<Boolean>(nothing)
|
||||
|
||||
checkSubtype<Any>(Unit)
|
||||
checkSubtype<Unit>(nothing)
|
||||
|
||||
checkSubtype<Any>(Exception())
|
||||
checkSubtype<Exception>(nothing)
|
||||
}
|
||||
// TESTCASE NUMBER: 3
|
||||
|
||||
class A3(val x : Int){
|
||||
|
||||
class Nested{
|
||||
fun case3(nothing: Nothing) {
|
||||
checkSubtype<Any>(this)
|
||||
checkSubtype<A3.Nested>(this)
|
||||
checkSubtype<A3.Nested>(nothing)
|
||||
}
|
||||
}
|
||||
|
||||
inner class AInner() {
|
||||
fun foo() = x
|
||||
fun case3(nothing: Nothing) {
|
||||
checkSubtype<Any>(this)
|
||||
checkSubtype<A3.AInner>(this)
|
||||
checkSubtype<A3.AInner>(nothing)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
companion object{
|
||||
private fun case3(nothing: Nothing) {
|
||||
checkSubtype<Any>(this)
|
||||
checkSubtype<A3.Companion>(this)
|
||||
checkSubtype<A3.Companion>(nothing)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 4
|
||||
class A4(val x: Int) {
|
||||
|
||||
interface AN
|
||||
|
||||
inner class AInner() {
|
||||
fun foo() = x
|
||||
}
|
||||
|
||||
companion object {}
|
||||
}
|
||||
|
||||
fun case4(a: A4, an: A4.AN, nothing: Nothing) {
|
||||
|
||||
checkSubtype<Any>(A4.Companion)
|
||||
checkSubtype<A4.Companion>(nothing)
|
||||
|
||||
checkSubtype<Any>(a.AInner())
|
||||
checkSubtype<A4.AInner>(nothing)
|
||||
|
||||
checkSubtype<Any>(an)
|
||||
checkSubtype<A4.AN>(nothing)
|
||||
}
|
||||
compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-rules/p-2/pos/1.1.kt
Vendored
+130
@@ -0,0 +1,130 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNREACHABLE_CODE -UNUSED_PARAMETER
|
||||
// SKIP_TXT
|
||||
|
||||
/*
|
||||
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-464
|
||||
* MAIN LINK: type-system, subtyping, subtyping-rules -> paragraph 2 -> sentence 1
|
||||
* SECONDARY LINKS: type-system, subtyping -> paragraph 2 -> sentence 1
|
||||
* type-system, subtyping -> paragraph 2 -> sentence 2
|
||||
* PRIMARY LINKS: type-system, subtyping, subtyping-rules -> paragraph 2 -> sentence 2
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: type T is subtype of Any and Noting is subtype of T
|
||||
* HELPERS: checkType
|
||||
*/
|
||||
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
class A
|
||||
|
||||
fun foo() : A = A()
|
||||
|
||||
interface AI{
|
||||
val ai0: String
|
||||
get() = ""
|
||||
}
|
||||
|
||||
val AI.ai1: Int
|
||||
get() = 1
|
||||
|
||||
|
||||
fun case1(a: A, ai: AI , nothing: Nothing) {
|
||||
|
||||
checkSubtype<Any>(a)
|
||||
checkSubtype<A>(nothing)
|
||||
|
||||
checkSubtype<Any>(foo())
|
||||
checkSubtype<A>(nothing)
|
||||
|
||||
checkSubtype<Any>(ai)
|
||||
checkSubtype<AI>(nothing)
|
||||
|
||||
checkSubtype<Any>(ai.ai0)
|
||||
checkSubtype<String>(nothing)
|
||||
|
||||
checkSubtype<Any>(ai.ai1)
|
||||
checkSubtype<Int>(nothing)
|
||||
|
||||
checkSubtype<Any>(nothing)
|
||||
checkSubtype<Nothing>(nothing)
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
fun case2( nothing: Nothing) {
|
||||
|
||||
checkSubtype<Any>("a")
|
||||
checkSubtype<String>(nothing)
|
||||
checkSubtype<CharSequence>(nothing)
|
||||
checkSubtype<CharSequence>("")
|
||||
|
||||
checkSubtype<Any>(1)
|
||||
checkSubtype<Int>(nothing)
|
||||
|
||||
checkSubtype<Any>(1.0)
|
||||
checkSubtype<Double>(nothing)
|
||||
|
||||
checkSubtype<Any>(true)
|
||||
checkSubtype<Boolean>(nothing)
|
||||
|
||||
checkSubtype<Any>(Unit)
|
||||
checkSubtype<Unit>(nothing)
|
||||
|
||||
checkSubtype<Any>(Exception())
|
||||
checkSubtype<Exception>(nothing)
|
||||
}
|
||||
// TESTCASE NUMBER: 3
|
||||
|
||||
class A3(val x : Int){
|
||||
|
||||
class Nested{
|
||||
fun case3(nothing: Nothing) {
|
||||
checkSubtype<Any>(this)
|
||||
checkSubtype<A3.Nested>(this)
|
||||
checkSubtype<A3.Nested>(nothing)
|
||||
}
|
||||
}
|
||||
|
||||
inner class AInner() {
|
||||
fun foo() = x
|
||||
fun case3(nothing: Nothing) {
|
||||
checkSubtype<Any>(this)
|
||||
checkSubtype<A3.AInner>(this)
|
||||
checkSubtype<A3.AInner>(nothing)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
companion object{
|
||||
private fun case3(nothing: Nothing) {
|
||||
checkSubtype<Any>(this)
|
||||
checkSubtype<A3.Companion>(this)
|
||||
checkSubtype<A3.Companion>(nothing)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 4
|
||||
class A4(val x: Int) {
|
||||
|
||||
interface AN
|
||||
|
||||
inner class AInner() {
|
||||
fun foo() = x
|
||||
}
|
||||
|
||||
companion object {}
|
||||
}
|
||||
|
||||
fun case4(a: A4, an: A4.AN, nothing: Nothing) {
|
||||
|
||||
checkSubtype<Any>(A4.Companion)
|
||||
checkSubtype<A4.Companion>(nothing)
|
||||
|
||||
checkSubtype<Any>(a.AInner())
|
||||
checkSubtype<A4.AInner>(nothing)
|
||||
|
||||
checkSubtype<Any>(an)
|
||||
checkSubtype<A4.AN>(nothing)
|
||||
}
|
||||
Vendored
+29
@@ -10,6 +10,35 @@
|
||||
"unexpectedBehaviour": false,
|
||||
"linkType": "primary",
|
||||
"helpers": "checkType, functions"
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-213",
|
||||
"casesNumber": 2,
|
||||
"description": "Check of Nothing type is a subtype of any types",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/type-system/type-kinds/built-in-types/kotlin.nothing/p-1/pos/1.1.kt",
|
||||
"unexpectedBehaviour": false,
|
||||
"linkType": "secondary",
|
||||
"helpers": "checkType, functions"
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-464",
|
||||
"casesNumber": 4,
|
||||
"description": "type T is subtype of Any and Noting is subtype of T",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-rules/p-2/pos/1.1.kt",
|
||||
"unexpectedBehaviour": false,
|
||||
"linkType": "main",
|
||||
"helpers": "checkType"
|
||||
}
|
||||
],
|
||||
"2": [
|
||||
{
|
||||
"specVersion": "0.1-464",
|
||||
"casesNumber": 4,
|
||||
"description": "type T is subtype of Any and Noting is subtype of T",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-rules/p-2/pos/1.1.kt",
|
||||
"unexpectedBehaviour": false,
|
||||
"linkType": "primary",
|
||||
"helpers": "checkType"
|
||||
}
|
||||
],
|
||||
"3": [
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"2": {
|
||||
"pos": {
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-464",
|
||||
"casesNumber": 4,
|
||||
"description": "type T is subtype of Any and Noting is subtype of T",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-rules/p-2/pos/1.1.kt",
|
||||
"unexpectedBehaviour": false,
|
||||
"linkType": "secondary",
|
||||
"helpers": "checkType"
|
||||
}
|
||||
],
|
||||
"2": [
|
||||
{
|
||||
"specVersion": "0.1-464",
|
||||
"casesNumber": 4,
|
||||
"description": "type T is subtype of Any and Noting is subtype of T",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-rules/p-2/pos/1.1.kt",
|
||||
"unexpectedBehaviour": false,
|
||||
"linkType": "secondary",
|
||||
"helpers": "checkType"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -9,6 +9,7 @@
|
||||
*
|
||||
* SPEC VERSION: 0.1-213
|
||||
* MAIN LINK: type-system, type-kinds, built-in-types, kotlin.nothing -> paragraph 1 -> sentence 1
|
||||
* SECONDARY LINKS: type-system, subtyping, subtyping-rules -> paragraph 2 -> sentence 1
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: Check of Nothing type is a subtype of any types
|
||||
* HELPERS: checkType, functions
|
||||
|
||||
Reference in New Issue
Block a user