From 0488dc985fd727bdeafd8e306e73a5ea2c122d70 Mon Sep 17 00:00:00 2001 From: "anastasiia.spaseeva" Date: Tue, 28 Jul 2020 11:14:46 +0300 Subject: [PATCH] [Spec tests] Add tests for intersection and OR --- .../operator-call/p-1/neg/2.4.fir.kt | 4 +- .../operator-call/p-1/neg/2.5.fir.kt | 4 +- .../operator-call/p-1/neg/2.6.fir.kt | 4 +- .../operator-call/p-1/neg/2.7.fir.kt | 4 +- .../operator-call/p-1/neg/2.8.fir.kt | 8 +- .../operator-call/p-1/neg/2.9.fir.kt | 2 +- .../p-9/neg/2.3.fir.kt | 19 ++ .../algorithm-of-msc-selection/p-9/neg/2.3.kt | 28 +++ .../algorithm-of-msc-selection/testsMap.json | 8 + .../p-1/pos/1.1.fir.kt | 64 +++++++ .../p-1/pos/1.1.kt | 74 ++++++++ .../p-1/pos/1.2.fir.kt | 155 ++++++++++++++++ .../p-1/pos/1.2.kt | 165 ++++++++++++++++++ .../p-1/pos/1.3.fir.kt | 120 +++++++++++++ .../p-1/pos/1.3.kt | 130 ++++++++++++++ .../testsMap.json | 68 ++++++++ .../DiagnosticsTestSpecGenerated.java | 59 +++++++ .../FirDiagnosticsTestSpecGenerated.java | 59 +++++++ 18 files changed, 962 insertions(+), 13 deletions(-) create mode 100644 compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/p-9/neg/2.3.fir.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/p-9/neg/2.3.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.1.fir.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.1.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.2.fir.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.2.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.3.fir.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.3.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/testsMap.json diff --git a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.4.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.4.fir.kt index d758a058994..dca1e020a8b 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.4.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.4.fir.kt @@ -15,9 +15,9 @@ import LibPackCase1.b.* fun case1 (){ var b: B? = B() - b += { C() } + b += { C() } - b += {1} + b += {1} } class B { diff --git a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.5.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.5.fir.kt index 375ff17f305..5dcc3461f9d 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.5.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.5.fir.kt @@ -10,9 +10,9 @@ import LibPackCase1.a.* import LibPackCase1.b.* fun case1 (){ var b: B? = null - b += { C() } + b += { C() } - b += {1} + b += {1} } class B { diff --git a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.6.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.6.fir.kt index c76c7352085..4434928a706 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.6.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.6.fir.kt @@ -15,9 +15,9 @@ import LibPackCase1.b.* fun case1 (){ var b: B? = B() - b += { C() } + b += { C() } - b += {1} + b += {1} } class B { diff --git a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.7.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.7.fir.kt index c884bb5a4e2..650626deefb 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.7.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.7.fir.kt @@ -15,9 +15,9 @@ import LibPackCase1.b.plusAssign fun case1 (){ var b: B? = B() - b += { C() } + b += { C() } - b += {1} + b += {1} } class B { diff --git a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.8.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.8.fir.kt index 7c940a12ed0..b57c07ce3ad 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.8.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.8.fir.kt @@ -15,8 +15,8 @@ import LibPackCase1.b.plusAssign fun case1 (){ var b: B = B() - b +={ C() } - b +={ 1 } + b +={ C() } + b +={ 1 } } class B @@ -48,8 +48,8 @@ import LibPackCase2.b.plusAssign fun case2 (){ var b: B = B() - b +={ C() } - b +={ 1 } + b +={ C() } + b +={ 1 } b.plusAssign{ C() } } diff --git a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.9.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.9.fir.kt index 5dec7278f67..4992c32689d 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.9.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-1/neg/2.9.fir.kt @@ -14,7 +14,7 @@ import LibPackCase1.a.plusAssign fun case1 (){ var b: B = B() - b +={ C() } + b +={ C() } b +={ 1 } } diff --git a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/p-9/neg/2.3.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/p-9/neg/2.3.fir.kt new file mode 100644 index 00000000000..b75cf2db4a0 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/p-9/neg/2.3.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION +// SKIP_TXT + + +// TESTCASE NUMBER: 1 +interface A1 +interface B1 + +fun case1(x: Any) { + fun A1.foo(): kotlin.Int = 1 //(1) + fun B1.foo(): kotlin.Int = 2 //(2) + fun Any.foo(): kotlin.String = "Any" //(3) + x.foo() // to (3) + x.foo() + if (x is B1 && x is A1) { + x.foo() + } +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/p-9/neg/2.3.kt b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/p-9/neg/2.3.kt new file mode 100644 index 00000000000..c3aa78c190e --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/p-9/neg/2.3.kt @@ -0,0 +1,28 @@ +// !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-464 + * MAIN LINK: overload-resolution, choosing-the-most-specific-candidate-from-the-overload-candidate-set, algorithm-of-msc-selection -> paragraph 9 -> sentence 2 + * NUMBER: 3 + * DESCRIPTION: receiver of intersection type ambuguity + */ + +// TESTCASE NUMBER: 1 +interface A1 +interface B1 + +fun case1(x: Any) { + fun A1.foo(): kotlin.Int = 1 //(1) + fun B1.foo(): kotlin.Int = 2 //(2) + fun Any.foo(): kotlin.String = "Any" //(3) + x.foo() // to (3) + x.foo() + if (x is B1 && x is A1) { + x.foo() + } +} + diff --git a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/testsMap.json b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/testsMap.json index 83764222989..618ad624e4e 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/testsMap.json +++ b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/testsMap.json @@ -1008,6 +1008,14 @@ "unexpectedBehaviour": false, "linkType": "main" }, + { + "specVersion": "0.1-464", + "casesNumber": 1, + "description": "receiver of intersection type ambuguity", + "path": "compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/p-9/neg/2.3.kt", + "unexpectedBehaviour": false, + "linkType": "main" + }, { "specVersion": "0.1-448", "casesNumber": 2, diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.1.fir.kt new file mode 100644 index 00000000000..fc074703509 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.1.fir.kt @@ -0,0 +1,64 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION +// SKIP_TXT + + +/* + * TESTCASE NUMBER: 1 + * ISSUES: KT-39405 + */ +interface I{ + +} +enum class EA : I { + A +} +enum class EB : I { + B +} +fun case1(a: Any) { + val x1 = if (true) EA.A else EB.B + checkSubtype>(x1) + checkSubtype(x1) + ")!>x1 + + val x2 = if (true) EB.B else EA.A + checkSubtype>(x2) + checkSubtype(x2) + ")!>x2 + + val x3 = when(a){ + is Int -> EA.A + else -> EB.B + } + checkSubtype>(x3) + checkSubtype(x3) + ")!>x3 + +} +/* + * TESTCASE NUMBER: 2 + */ +enum class A { + A +} +interface IB +enum class B : IB { + B +} +fun case2(a: Any) { + val x1 = if (true) A.A else B.B + checkSubtype>(x1) + ")!>x1 + + val x2 = if (true) B.B else A.A + checkSubtype>(x2) + ")!>x2 + + val x3 = when(a){ + is Int -> A.A + else -> B.B + } + checkSubtype>(x3) + ")!>x3 +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.1.kt new file mode 100644 index 00000000000..7bd51dddcc7 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.1.kt @@ -0,0 +1,74 @@ +// !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-464 + * MAIN LINK: type-system, subtyping, subtyping-for-intersection-types -> paragraph 1 -> sentence 1 + * PRIMARY LINKS: type-system, subtyping, subtyping-for-intersection-types -> paragraph 2 -> sentence 3 + * NUMBER: 1 + * DESCRIPTION: intersection type inferred for enum classes + * HELPERS: checkType, functions + */ + +/* + * TESTCASE NUMBER: 1 + * ISSUES: KT-39405 + */ +interface I{ + +} +enum class EA : I { + A +} +enum class EB : I { + B +} +fun case1(a: Any) { + val x1 = if (true) EA.A else EB.B + checkSubtype>(x1) + checkSubtype(x1) + & I}")!>x1 + + val x2 = if (true) EB.B else EA.A + checkSubtype>(x2) + checkSubtype(x2) + & I}")!>x2 + + val x3 = when(a){ + is Int -> EA.A + else -> EB.B + } + checkSubtype>(x3) + checkSubtype(x3) + & I}")!>x3 + +} +/* + * TESTCASE NUMBER: 2 + */ +enum class A { + A +} +interface IB +enum class B : IB { + B +} +fun case2(a: Any) { + val x1 = if (true) A.A else B.B + checkSubtype>(x1) + ")!>x1 + + val x2 = if (true) B.B else A.A + checkSubtype>(x2) + ")!>x2 + + val x3 = when(a){ + is Int -> A.A + else -> B.B + } + checkSubtype>(x3) + ")!>x3 +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.2.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.2.fir.kt new file mode 100644 index 00000000000..ceddf4461d9 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.2.fir.kt @@ -0,0 +1,155 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION +// SKIP_TXT + + + +// TESTCASE NUMBER: 1 +fun case1() { + val x = case1(object : A1, B1 {}) + checkSubtype(x) + checkSubtype(x) +} + + +interface A1 { + fun fooA() = "A" +} + +interface B1 { + fun fooB() = "B" +} + +fun case1(case: T): T where T : A1, T : B1 = case + +// TESTCASE NUMBER: 2 +fun case2() { + fun case2(case: T): T where T : A2, T : B2 = case + + val x = case2(C2()) + checkSubtype(x) + checkSubtype(x) +} + +class C2: A2, B2 + +interface A2 { + fun fooA() = "A" +} + +interface B2 { + fun fooB() = "B" +} + +// TESTCASE NUMBER: 3 +fun case3() { + val x = case3(object : A3, B3 {}) + checkSubtype(x) + checkSubtype(x) +} + + +interface A3 { + fun fooA() = "A" +} + +interface B3 { + fun fooB() = "B" +} + +fun case3(case: T): T where T : A3, T : B3 = case + +// TESTCASE NUMBER: 4 +fun case4() { + fun case4(case: T): T where T : A4, T : B4 = case + + val x = case4(C4()) + checkSubtype(x) + checkSubtype(x) +} + +class C4: A4, B4 + +interface A4 { + fun fooA() = "A" +} + +interface B4 { + fun fooB() = "B" +} + + + +// TESTCASE NUMBER: 5 +fun case5() { + val x = "" case5 object : A5, B5 {} + checkSubtype(x) + checkSubtype(x) +} + + +interface A5 { + fun fooA() = "A" +} + +interface B5 { + fun fooB() = "B" +} + +infix fun CharSequence.case5(case: T): T where T : A5, T : B5 = case + +// TESTCASE NUMBER: 6 +fun case6() { + infix fun CharSequence.case6(case: T): T where T : A6, T : B6 = case + + val x = "" case6 C6() + checkSubtype(x) + checkSubtype(x) +} + +class C6: A6, B6 + +interface A6 { + fun fooA() = "A" +} + +interface B6 { + fun fooB() = "B" +} + +// TESTCASE NUMBER: 7 +fun case7() { + val x = case7(object : A7, B7 {}) + checkSubtype(x) + checkSubtype(x) +} + + +interface A7 { + fun fooA() = "A" +} + +interface B7 { + fun fooB() = "B" +} + +fun case7(case: T): T where T : A7, T : B7 = case + +// TESTCASE NUMBER: 8 +fun case8() { + infix fun CharSequence.case8(case: T): T where T : A8, T : B8 = case + + val x = "" case8 C8() + checkSubtype(x) + checkSubtype(x) +} + +class C8: A8, B8 + +interface A8 { + fun fooA() = "A" +} + +interface B8 { + fun fooB() = "B" +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.2.kt b/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.2.kt new file mode 100644 index 00000000000..920a0e4fe44 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.2.kt @@ -0,0 +1,165 @@ +// !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-464 + * MAIN LINK: type-system, subtyping, subtyping-for-intersection-types -> paragraph 1 -> sentence 1 + * PRIMARY LINKS: type-system, subtyping, subtyping-for-intersection-types -> paragraph 2 -> sentence 3 + * NUMBER: 2 + * DESCRIPTION: intersection type inferred for parametrized functions + * HELPERS: checkType, functions + */ + + +// TESTCASE NUMBER: 1 +fun case1() { + val x = case1(object : A1, B1 {}) + checkSubtype(x) + checkSubtype(x) +} + + +interface A1 { + fun fooA() = "A" +} + +interface B1 { + fun fooB() = "B" +} + +fun case1(case: T): T where T : A1, T : B1 = case + +// TESTCASE NUMBER: 2 +fun case2() { + fun case2(case: T): T where T : A2, T : B2 = case + + val x = case2(C2()) + checkSubtype(x) + checkSubtype(x) +} + +class C2: A2, B2 + +interface A2 { + fun fooA() = "A" +} + +interface B2 { + fun fooB() = "B" +} + +// TESTCASE NUMBER: 3 +fun case3() { + val x = case3(object : A3, B3 {}) + checkSubtype(x) + checkSubtype(x) +} + + +interface A3 { + fun fooA() = "A" +} + +interface B3 { + fun fooB() = "B" +} + +fun case3(case: T): T where T : A3, T : B3 = case + +// TESTCASE NUMBER: 4 +fun case4() { + fun case4(case: T): T where T : A4, T : B4 = case + + val x = case4(C4()) + checkSubtype(x) + checkSubtype(x) +} + +class C4: A4, B4 + +interface A4 { + fun fooA() = "A" +} + +interface B4 { + fun fooB() = "B" +} + + + +// TESTCASE NUMBER: 5 +fun case5() { + val x = "" case5 object : A5, B5 {} + checkSubtype(x) + checkSubtype(x) +} + + +interface A5 { + fun fooA() = "A" +} + +interface B5 { + fun fooB() = "B" +} + +infix fun CharSequence.case5(case: T): T where T : A5, T : B5 = case + +// TESTCASE NUMBER: 6 +fun case6() { + infix fun CharSequence.case6(case: T): T where T : A6, T : B6 = case + + val x = "" case6 C6() + checkSubtype(x) + checkSubtype(x) +} + +class C6: A6, B6 + +interface A6 { + fun fooA() = "A" +} + +interface B6 { + fun fooB() = "B" +} + +// TESTCASE NUMBER: 7 +fun case7() { + val x = case7(object : A7, B7 {}) + checkSubtype(x) + checkSubtype(x) +} + + +interface A7 { + fun fooA() = "A" +} + +interface B7 { + fun fooB() = "B" +} + +fun case7(case: T): T where T : A7, T : B7 = case + +// TESTCASE NUMBER: 8 +fun case8() { + infix fun CharSequence.case8(case: T): T where T : A8, T : B8 = case + + val x = "" case8 C8() + checkSubtype(x) + checkSubtype(x) +} + +class C8: A8, B8 + +interface A8 { + fun fooA() = "A" +} + +interface B8 { + fun fooB() = "B" +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.3.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.3.fir.kt new file mode 100644 index 00000000000..f8a3c0ac2cf --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.3.fir.kt @@ -0,0 +1,120 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION +// SKIP_TXT + + +// TESTCASE NUMBER: 1 +// UNEXPECTED BEHAVIOUR +// ISSUES: KT-40074 +fun case1(x: Any) { + if (x is A1 && x is B1) { + checkSubtype(x) + checkSubtype(x) + + x // A1 & B1 & kotlin.Any + } +} + +interface A1 +interface B1 + +// TESTCASE NUMBER: 2 +fun case2(x: T) { + if (x is B2 && x is A2) { + checkSubtype(x) + checkSubtype(x) + checkSubtype(x) + + x //NI A2 & B2 & T & T!! OI A2 & B2 & T + x + } +} + +interface A2 +interface B2 + +// TESTCASE NUMBER: 3 +fun case3a(x: T) { + if (x is A3 && x is B3) { + + checkSubtype(x) + checkSubtype(x) + checkSubtype(x) + x + } +} +fun case3b(x: T) { + if (x is A3 && x is B3) { + + checkSubtype(x) + checkSubtype(x) + checkSubtype(x) + + x + } +} +fun case3c(x: T) { + if (x is A3 && x is B3) { + + checkSubtype(x) + checkSubtype(x) + checkSubtype(x) + + x + } +} + +interface B3 +interface A3 + +// TESTCASE NUMBER: 4 + +fun case4(x: C?) { + if (x is B4 && x is A4) { + x + x + x.foo() + } +} + +interface A4 +interface B4 + +class C : A4, B4 { + fun foo() = "" +} + +// TESTCASE NUMBER: 5 + +fun case5(x: T) { + if (x is B5 && x is A5) { + x + x + } +} + +interface A5 : I5 +interface B5 : I5 +interface I5 +class C5 : A5, B5 { + fun foo() = "" +} + +// TESTCASE NUMBER: 6 + +fun case6(case: T): T where T : A6?, T : B6? = case + +fun foo(case: T): T? = case + +fun test6(x: T) where T : B6? { + if (x is A6?) { + (x as C6).foo() + } +} + +interface A6 +interface B6 + +fun C6?.foo(vararg x: Int) = println("hehe") + +class C6 : A6, B6 {} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.3.kt b/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.3.kt new file mode 100644 index 00000000000..4e109f90617 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.3.kt @@ -0,0 +1,130 @@ +// !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-464 + * MAIN LINK: type-system, subtyping, subtyping-for-intersection-types -> paragraph 1 -> sentence 1 + * PRIMARY LINKS: type-system, subtyping, subtyping-for-intersection-types -> paragraph 2 -> sentence 3 + * NUMBER: 3 + * DESCRIPTION: intersection type inferred for function + * HELPERS: checkType, functions + */ + +// TESTCASE NUMBER: 1 +// UNEXPECTED BEHAVIOUR +// ISSUES: KT-40074 +fun case1(x: Any) { + if (x is A1 && x is B1) { + checkSubtype(x) + checkSubtype(x) + + x // A1 & B1 & kotlin.Any + } +} + +interface A1 +interface B1 + +// TESTCASE NUMBER: 2 +fun case2(x: T) { + if (x is B2 && x is A2) { + checkSubtype(x) + checkSubtype(x) + checkSubtype(x) + + x //NI A2 & B2 & T & T!! OI A2 & B2 & T + x + } +} + +interface A2 +interface B2 + +// TESTCASE NUMBER: 3 +fun case3a(x: T) { + if (x is A3 && x is B3) { + + checkSubtype(x) + checkSubtype(x) + checkSubtype(x) + x + } +} +fun case3b(x: T) { + if (x is A3 && x is B3) { + + checkSubtype(x) + checkSubtype(x) + checkSubtype(x) + + x + } +} +fun case3c(x: T) { + if (x is A3 && x is B3) { + + checkSubtype(x) + checkSubtype(x) + checkSubtype(x) + + x + } +} + +interface B3 +interface A3 + +// TESTCASE NUMBER: 4 + +fun case4(x: C?) { + if (x is B4 && x is A4) { + x + x + x.foo() + } +} + +interface A4 +interface B4 + +class C : A4, B4 { + fun foo() = "" +} + +// TESTCASE NUMBER: 5 + +fun case5(x: T) { + if (x is B5 && x is A5) { + x + x + } +} + +interface A5 : I5 +interface B5 : I5 +interface I5 +class C5 : A5, B5 { + fun foo() = "" +} + +// TESTCASE NUMBER: 6 + +fun case6(case: T): T where T : A6?, T : B6? = case + +fun foo(case: T): T? = case + +fun test6(x: T) where T : B6? { + if (x is A6?) { + (x as C6).foo() + } +} + +interface A6 +interface B6 + +fun C6?.foo(vararg x: Int) = println("hehe") + +class C6 : A6, B6 {} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/testsMap.json b/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/testsMap.json new file mode 100644 index 00000000000..323bc3383f3 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/testsMap.json @@ -0,0 +1,68 @@ +{ + "1": { + "pos": { + "1": [ + { + "specVersion": "0.1-464", + "casesNumber": 8, + "description": "intersection type inferred for parametrized functions", + "path": "compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.2.kt", + "unexpectedBehaviour": false, + "linkType": "main", + "helpers": "checkType, functions" + }, + { + "specVersion": "0.1-464", + "casesNumber": 6, + "description": "intersection type inferred for function", + "path": "compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.3.kt", + "unexpectedBehaviour": false, + "linkType": "main", + "helpers": "checkType, functions" + }, + { + "specVersion": "0.1-464", + "casesNumber": 2, + "description": "intersection type inferred for enum classes", + "path": "compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.1.kt", + "unexpectedBehaviour": false, + "linkType": "main", + "helpers": "checkType, functions" + } + ] + } + }, + "2": { + "pos": { + "3": [ + { + "specVersion": "0.1-464", + "casesNumber": 8, + "description": "intersection type inferred for parametrized functions", + "path": "compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.2.kt", + "unexpectedBehaviour": false, + "linkType": "primary", + "helpers": "checkType, functions" + }, + { + "specVersion": "0.1-464", + "casesNumber": 6, + "description": "intersection type inferred for function", + "path": "compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.3.kt", + "unexpectedBehaviour": false, + "linkType": "primary", + "helpers": "checkType, functions" + }, + { + "specVersion": "0.1-464", + "casesNumber": 2, + "description": "intersection type inferred for enum classes", + "path": "compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.1.kt", + "unexpectedBehaviour": false, + "linkType": "primary", + "helpers": "checkType, functions" + } + ] + } + } +} \ No newline at end of file diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java index b57c817ce47..07c6653d7a6 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java @@ -4754,6 +4754,11 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { runTest("compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/p-9/neg/2.2.kt"); } + @TestMetadata("2.3.kt") + public void test2_3() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/p-9/neg/2.3.kt"); + } + public void testAllFilesPresentInNeg() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/p-9/neg"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } @@ -5731,6 +5736,60 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true, "subtyping-for-nullable-types"); } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Subtyping_for_intersection_types extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInSubtyping_for_intersection_types() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class P_1 extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInP_1() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Pos extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + @TestMetadata("1.1.kt") + public void test1_1() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.1.kt"); + } + + @TestMetadata("1.2.kt") + public void test1_2() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.2.kt"); + } + + @TestMetadata("1.3.kt") + public void test1_3() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.3.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + } + } + } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-rules") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/FirDiagnosticsTestSpecGenerated.java b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/FirDiagnosticsTestSpecGenerated.java index a947b9f8d78..525f756b2c1 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/FirDiagnosticsTestSpecGenerated.java +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/FirDiagnosticsTestSpecGenerated.java @@ -4754,6 +4754,11 @@ public class FirDiagnosticsTestSpecGenerated extends AbstractFirDiagnosticsTestS runTest("compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/p-9/neg/2.2.kt"); } + @TestMetadata("2.3.kt") + public void test2_3() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/p-9/neg/2.3.kt"); + } + public void testAllFilesPresentInNeg() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/overload-resolution/choosing-the-most-specific-candidate-from-the-overload-candidate-set/algorithm-of-msc-selection/p-9/neg"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } @@ -5731,6 +5736,60 @@ public class FirDiagnosticsTestSpecGenerated extends AbstractFirDiagnosticsTestS KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true, "subtyping-for-nullable-types"); } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Subtyping_for_intersection_types extends AbstractFirDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInSubtyping_for_intersection_types() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class P_1 extends AbstractFirDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInP_1() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Pos extends AbstractFirDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + @TestMetadata("1.1.kt") + public void test1_1() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.1.kt"); + } + + @TestMetadata("1.2.kt") + public void test1_2() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.2.kt"); + } + + @TestMetadata("1.3.kt") + public void test1_3() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos/1.3.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-for-intersection-types/p-1/pos"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + } + } + } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/type-system/subtyping/subtyping-rules") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)