[Spec tests] Add tests for abstract classes
This commit is contained in:
+25
-2
@@ -6,7 +6,7 @@
|
||||
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-213
|
||||
* PLACE: declarations, classifier-declaration, class-declaration, abstract-classes -> paragraph 1 -> sentence 1
|
||||
* PLACE: declarations, classifier-declaration, class-declaration, abstract-classes -> paragraph 1 -> sentence 2
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: check abstract classes can have abstract not implemented members
|
||||
*/
|
||||
@@ -31,4 +31,27 @@ class Impl : Base() {
|
||||
|
||||
fun case1() {
|
||||
val impl = Impl()
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
abstract class Case2() : BaseCase2() {
|
||||
abstract fun boo()
|
||||
public abstract override fun foo()
|
||||
}
|
||||
|
||||
abstract class BaseCase2() {
|
||||
abstract val a: String
|
||||
protected abstract fun foo()
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
|
||||
interface MyInterfaceCase3 {
|
||||
abstract fun foo(): String
|
||||
abstract val a: String
|
||||
}
|
||||
|
||||
abstract class MyImplCase3() : MyInterfaceCase3 {
|
||||
abstract fun boo()
|
||||
}
|
||||
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
// !LANGUAGE: +NewInference +ProhibitInvisibleAbstractMethodsInSuperclasses
|
||||
// !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-213
|
||||
* PLACE: declarations, classifier-declaration, class-declaration, abstract-classes -> paragraph 2 -> sentence 1
|
||||
* RELEVANT PLACES: inheritance, overriding -> paragraph 7 -> sentence 1
|
||||
* NUMBER: 10
|
||||
* DESCRIPTION: Abstract classes may contain one or more abstract members, which should be implemented in a subtype of this abstract class
|
||||
* ISSUES: KT-27825
|
||||
*/
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
<!ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED!>class Case1<!>() : BaseCase1(), InterfaceCase1 {}
|
||||
|
||||
abstract class BaseCase1() {
|
||||
abstract fun foo(): String
|
||||
abstract val a: String
|
||||
}
|
||||
|
||||
interface InterfaceCase1 {
|
||||
fun foo() = "foo"
|
||||
val a: String
|
||||
get() = "a"
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
class Case2Outer {
|
||||
val v = "v"
|
||||
|
||||
abstract class Case2Base() {
|
||||
abstract fun foo(): String
|
||||
}
|
||||
|
||||
inner
|
||||
<!ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED!>class A<!>() : Case2Base() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
fun case3() {
|
||||
<!ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED!>object<!> : CaseOuter.CaseBase() {}.outerFoo()
|
||||
}
|
||||
|
||||
<!ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED!>class B<!>() : CaseOuter.CaseBase() {}
|
||||
|
||||
sealed class CaseOuter {
|
||||
val v = "v"
|
||||
abstract fun outerFoo();
|
||||
|
||||
abstract class CaseBase() : CaseOuter() {
|
||||
abstract fun foo(): String
|
||||
}
|
||||
|
||||
<!ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED!>class A<!>() : CaseBase() {
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
// !LANGUAGE: +NewInference +ProhibitInvisibleAbstractMethodsInSuperclasses
|
||||
// !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-213
|
||||
* PLACE: declarations, classifier-declaration, class-declaration, abstract-classes -> paragraph 2 -> sentence 1
|
||||
* RELEVANT PLACES: inheritance, overriding -> paragraph 7 -> sentence 1
|
||||
* NUMBER: 9
|
||||
* DESCRIPTION: Abstract classes may contain one or more abstract members, which should be implemented in a subtype of this abstract class
|
||||
* ISSUES: KT-27825, KT-35325
|
||||
*/
|
||||
|
||||
// MODULE: libModule
|
||||
// FILE: libModule/BaseJava1.java
|
||||
package libModule;
|
||||
|
||||
public abstract class BaseJava1 {
|
||||
/*package-private*/ abstract void boojava();
|
||||
}
|
||||
|
||||
|
||||
// FILE: BaseKotlin1.kt
|
||||
package libModule
|
||||
|
||||
public abstract class BaseKotlin1 {
|
||||
internal abstract fun bookotlin()
|
||||
}
|
||||
|
||||
// MODULE: mainModule(libModule)
|
||||
// FILE: JavaClassWithAbstractKotlinClass.java
|
||||
package mainModule
|
||||
import libModule.*
|
||||
|
||||
/*
|
||||
* TESTCASE NUMBER: 1
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
* ISSUES: KT-35325
|
||||
*/
|
||||
public class JavaClassWithAbstractKotlinClass {
|
||||
|
||||
public void zoo()
|
||||
{
|
||||
//todo: INVISIBLE_ABSTRACT_MEMBER_FROM_SUPER should be expected
|
||||
BaseKotlin1 baseKotlin = new BaseKotlin1() {};
|
||||
|
||||
BaseKotlin1 baseKotlin = new BaseKotlinImpl();
|
||||
baseKotlin.bookotlin$libModule(); //highlight Error: usage of Kotlin internal declaration from different module
|
||||
|
||||
BaseKotlinImpl baseKotlinImpl = new BaseKotlinImpl();
|
||||
baseKotlinImpl.bookotlin$libModule(); //there is no any Error, but should be
|
||||
}
|
||||
|
||||
class BaseKotlinImpl extends BaseKotlin1 {
|
||||
@Override
|
||||
public void bookotlin$libModule() {
|
||||
System.out.println("wefrgth");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FILE: KotlinClassWithAbstractJavaClass.kt
|
||||
package mainModule
|
||||
import libModule.*
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
class KotlinClassWithAbstractJavaClass() {
|
||||
fun foo() {
|
||||
val baseJava1 = <!INVISIBLE_ABSTRACT_MEMBER_FROM_SUPER!>object<!> : BaseJava1() {}
|
||||
val baseKotlin = <!INVISIBLE_ABSTRACT_MEMBER_FROM_SUPER!>object<!> : BaseKotlin1() {}
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
// !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: declarations, classifier-declaration, class-declaration, abstract-classes -> paragraph 2 -> sentence 1
|
||||
* NUMBER: 3
|
||||
* DESCRIPTION: Abstract classes may contain one or more abstract members, which should be implemented in a subtype of this abstract class
|
||||
* HELPERS: checkType, functions
|
||||
*/
|
||||
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
// NOTE: attempt to implement inner abstract class as anonymous class
|
||||
open class MainCase1() {
|
||||
private val priv = "privet"
|
||||
|
||||
val implVal = object : MainCase1.InnerAbstractBase() {
|
||||
override fun foo(s: String) {
|
||||
println("object {$s}")
|
||||
}
|
||||
}
|
||||
|
||||
abstract inner class InnerAbstractBase() {
|
||||
protected abstract fun foo(s: String)
|
||||
fun boo() {
|
||||
foo(priv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun case1() {
|
||||
val main = MainCase1()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("MainCase1.InnerAbstractBase")!>main.implVal<!>.boo()
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
//NOTE: attempt to implement inner abstract class in init block
|
||||
fun case2() {
|
||||
val main = MainCase2()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("MainCase2.InnerAbstractBase")!>main.impl<!>.boo()
|
||||
}
|
||||
|
||||
|
||||
open class MainCase2() {
|
||||
private val priv = "privet"
|
||||
|
||||
abstract inner class InnerAbstractBase() {
|
||||
protected abstract fun foo(s: String)
|
||||
fun boo() {
|
||||
foo(priv)
|
||||
}
|
||||
}
|
||||
|
||||
var impl: InnerAbstractBase
|
||||
|
||||
init {
|
||||
impl = object : MainCase2.InnerAbstractBase() {
|
||||
override fun foo(s: String) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TESTCASE NUMBER: 3
|
||||
// NOTE: attempt to inherit inner abstract class as another inner class
|
||||
fun case3() {
|
||||
val main = MainCase3()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("MainCase3.ImplInnerAbstractBase")!>main.ImplInnerAbstractBase()<!>.boo()
|
||||
}
|
||||
|
||||
open class MainCase3() {
|
||||
private val priv = "privet"
|
||||
|
||||
abstract inner class InnerAbstractBase() {
|
||||
protected abstract fun foo(s: String)
|
||||
fun boo() {
|
||||
foo(priv)
|
||||
}
|
||||
}
|
||||
|
||||
inner class ImplInnerAbstractBase : MainCase3.InnerAbstractBase() {
|
||||
override fun foo(s: String) {
|
||||
println("ImplInnerAbstractBase {$s}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TESTCASE NUMBER: 4
|
||||
// NOTE: attempt to inherit inner abstract class in a outer class function
|
||||
fun case4() {
|
||||
val main = MainCase4()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("MainCase4.InnerAbstractBase")!>main.zoo()<!>.boo()
|
||||
}
|
||||
|
||||
|
||||
open class MainCase4() {
|
||||
private val priv = "privet"
|
||||
|
||||
abstract inner class InnerAbstractBase() {
|
||||
protected abstract fun foo(s: String)
|
||||
fun boo() {
|
||||
foo(priv)
|
||||
}
|
||||
}
|
||||
|
||||
fun zoo(): MainCase4.InnerAbstractBase {
|
||||
class ImplInnerAbstractBaseZoo : MainCase4.InnerAbstractBase() {
|
||||
override fun foo(s: String) {
|
||||
println("zoo fun: {$s}")
|
||||
}
|
||||
}
|
||||
return ImplInnerAbstractBaseZoo()
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
// !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: declarations, classifier-declaration, class-declaration, abstract-classes -> paragraph 2 -> sentence 1
|
||||
* NUMBER: 4
|
||||
* DESCRIPTION: Abstract classes may contain one or more abstract members, which should be implemented in a subtype of this abstract class
|
||||
* HELPERS: checkType, functions
|
||||
*/
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
|
||||
fun case1() {
|
||||
val c = Case1()
|
||||
c.a
|
||||
c.foo()
|
||||
}
|
||||
|
||||
abstract class BaseCase1() {
|
||||
fun foo() = "foo"
|
||||
val a: String
|
||||
get() = "a"
|
||||
}
|
||||
|
||||
interface MyInterface1 {
|
||||
abstract fun foo(): String
|
||||
abstract val a: String
|
||||
}
|
||||
|
||||
class Case1() : BaseCase1(), MyInterface1 {}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
|
||||
fun case2() {
|
||||
Case2Outer().A().foo()
|
||||
}
|
||||
|
||||
class Case2Outer {
|
||||
val v = "v"
|
||||
|
||||
abstract class Case2Base() {
|
||||
abstract fun foo(): String
|
||||
}
|
||||
|
||||
inner class A() : Case2Base() {
|
||||
override fun foo(): String {
|
||||
return v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
|
||||
fun case3() {
|
||||
CaseOuter.A().outerFoo()
|
||||
B().outerFoo()
|
||||
object : CaseOuter.CaseBase() {
|
||||
override fun foo(): String {
|
||||
return "c"
|
||||
}
|
||||
|
||||
override fun outerFoo() {}
|
||||
|
||||
}.outerFoo()
|
||||
}
|
||||
|
||||
sealed class CaseOuter {
|
||||
val v = "v"
|
||||
abstract fun outerFoo();
|
||||
|
||||
abstract class CaseBase() : CaseOuter() {
|
||||
abstract fun foo(): String
|
||||
}
|
||||
|
||||
class A() : CaseBase() {
|
||||
override fun foo(): String {
|
||||
return "A"
|
||||
}
|
||||
|
||||
override fun outerFoo() {
|
||||
println("outerFoo")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class B() : CaseOuter.CaseBase() {
|
||||
override fun foo(): String {
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun outerFoo() {
|
||||
}
|
||||
}
|
||||
+26
-2
@@ -26,10 +26,10 @@
|
||||
]
|
||||
},
|
||||
"pos": {
|
||||
"1": [
|
||||
"2": [
|
||||
{
|
||||
"specVersion": "0.1-213",
|
||||
"casesNumber": 1,
|
||||
"casesNumber": 3,
|
||||
"description": "check abstract classes can have abstract not implemented members",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
@@ -76,6 +76,18 @@
|
||||
"description": "Abstract classes may contain one or more abstract members, which should be implemented in a subtype of this abstract class",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-213",
|
||||
"casesNumber": 2,
|
||||
"description": "Abstract classes may contain one or more abstract members, which should be implemented in a subtype of this abstract class",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-213",
|
||||
"casesNumber": 2,
|
||||
"description": "Abstract classes may contain one or more abstract members, which should be implemented in a subtype of this abstract class",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-213",
|
||||
"casesNumber": 1,
|
||||
@@ -104,6 +116,18 @@
|
||||
"description": "Abstract classes may contain one or more abstract members, which should be implemented in a subtype of this abstract class",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-213",
|
||||
"casesNumber": 4,
|
||||
"description": "Abstract classes may contain one or more abstract members, which should be implemented in a subtype of this abstract class",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-213",
|
||||
"casesNumber": 2,
|
||||
"description": "Abstract classes may contain one or more abstract members, which should be implemented in a subtype of this abstract class",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-213",
|
||||
"casesNumber": 2,
|
||||
|
||||
+14
@@ -2,12 +2,26 @@
|
||||
"7": {
|
||||
"neg": {
|
||||
"1": [
|
||||
{
|
||||
"specVersion": "0.1-213",
|
||||
"casesNumber": 2,
|
||||
"description": "Abstract classes may contain one or more abstract members, which should be implemented in a subtype of this abstract class",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-2/neg/1.10.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-213",
|
||||
"casesNumber": 2,
|
||||
"description": "Abstract classes may contain one or more abstract members, which should be implemented in a subtype of this abstract class",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-2/neg/1.8.kt",
|
||||
"unexpectedBehaviour": false
|
||||
},
|
||||
{
|
||||
"specVersion": "0.1-213",
|
||||
"casesNumber": 2,
|
||||
"description": "Abstract classes may contain one or more abstract members, which should be implemented in a subtype of this abstract class",
|
||||
"path": "compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-2/neg/1.9.kt",
|
||||
"unexpectedBehaviour": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Generated
+23
-3
@@ -131,9 +131,9 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("1.1.kt")
|
||||
public void test1_1() throws Exception {
|
||||
runTest("compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-1/pos/1.1.kt");
|
||||
@TestMetadata("2.1.kt")
|
||||
public void test2_1() throws Exception {
|
||||
runTest("compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-1/pos/2.1.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInPos() throws Exception {
|
||||
@@ -167,6 +167,11 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec {
|
||||
runTest("compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-2/neg/1.1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("1.10.kt")
|
||||
public void test1_10() throws Exception {
|
||||
runTest("compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-2/neg/1.10.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("1.2.kt")
|
||||
public void test1_2() throws Exception {
|
||||
runTest("compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-2/neg/1.2.kt");
|
||||
@@ -202,6 +207,11 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec {
|
||||
runTest("compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-2/neg/1.8.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("1.9.kt")
|
||||
public void test1_9() throws Exception {
|
||||
runTest("compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-2/neg/1.9.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInNeg() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-2/neg"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
@@ -225,6 +235,16 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec {
|
||||
runTest("compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-2/pos/1.2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("1.3.kt")
|
||||
public void test1_3() throws Exception {
|
||||
runTest("compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-2/pos/1.3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("1.4.kt")
|
||||
public void test1_4() throws Exception {
|
||||
runTest("compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-2/pos/1.4.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInPos() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-2/pos"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user