diff --git a/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/2.1.kt b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/2.1.kt new file mode 100644 index 00000000000..125682ff4c1 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/2.1.kt @@ -0,0 +1,43 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-268 + * PLACE: overload-resolution, receivers -> paragraph 5 -> sentence 2 + * NUMBER: 1 + * DESCRIPTION: implicit this receiver has higher priority than any companion object receiver + */ + + +class Case1() : Case1Base() { + + companion object foo{ + var isCompanionObjectReceiverCalled = false + operator fun invoke() {} + fun foo() { + this.isCompanionObjectReceiverCalled = true + } + } + + fun case() { + foo() // resolved (1) + } +} + +open class Case1Base { + var isImplicitReceiverCalled = false + + fun foo() { + this.isImplicitReceiverCalled = true + } +} + +fun box(): String { + + val test = Case1() + test.case() + if (test.isImplicitReceiverCalled && !Case1.isCompanionObjectReceiverCalled) + return "OK" + return "NOK" +} diff --git a/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/2.2.kt b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/2.2.kt new file mode 100644 index 00000000000..7b79c2e628f --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/2.2.kt @@ -0,0 +1,43 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-268 + * PLACE: overload-resolution, receivers -> paragraph 5 -> sentence 2 + * NUMBER: 2 + * DESCRIPTION: implicit this receiver has higher priority than any companion object receiver + */ + + +class Case1() : Case1Base() { + var isImplicitReceiverCalled = false + + fun foo() { + this.isImplicitReceiverCalled = true + } // (1) + + fun case() { + foo() // resolved (1) + } +} + +open class Case1Base { + + companion object foo{ + var isCompanionObjectReceiverCalled = false + operator fun invoke() {} + fun foo() { + this.isCompanionObjectReceiverCalled = true + } + } + +} + +fun box(): String { + val test = Case1() + test.case() + if (test.isImplicitReceiverCalled && !Case1Base.isCompanionObjectReceiverCalled) + return "OK" + return "NOK" +} diff --git a/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/3.1.kt b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/3.1.kt new file mode 100644 index 00000000000..895d5b2d084 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/3.1.kt @@ -0,0 +1,33 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-268 + * PLACE:overload-resolution, receivers -> paragraph 5 -> sentence 3 + * NUMBER: 1 + * DESCRIPTION: Current class companion object receiver has higher priority than any of the superclass companion objects; + */ + +class Case() : CaseBase() { + + companion object foo{ + var isCaseCompanionCalled = false + fun foo(){isCaseCompanionCalled = true} + } +} + +open class CaseBase { + companion object foo { + var isCaseBaseReceiverCalled = false + fun foo() { this.isCaseBaseReceiverCalled = true } +// operator fun invoke() {} + } +} + +fun box(): String { + Case.foo.foo() + if (!CaseBase.isCaseBaseReceiverCalled && Case.isCaseCompanionCalled) + return "OK" + return "NOK" +} diff --git a/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/3.2.kt b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/3.2.kt new file mode 100644 index 00000000000..52b5fb99fd3 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/3.2.kt @@ -0,0 +1,36 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-268 + * PLACE:overload-resolution, receivers -> paragraph 5 -> sentence 3 + * NUMBER: 2 + * DESCRIPTION: Current class companion object receiver has higher priority than any of the superclass companion objects; + */ + +class Case() : CaseBase() { + + companion object foo{ + var isCaseCompanionCalled = false + fun foo(){isCaseCompanionCalled = true} + } + + fun test(): String{ + foo.foo() + if (!isCaseBaseReceiverCalled && isCaseCompanionCalled) + return "OK" + return "NOK" + } +} + +open class CaseBase { + companion object foo { + var isCaseBaseReceiverCalled = false + fun foo() { this.isCaseBaseReceiverCalled = true } + } +} + +fun box(): String { + return Case().test() +} diff --git a/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/4.1.kt b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/4.1.kt new file mode 100644 index 00000000000..0797920d79e --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/4.1.kt @@ -0,0 +1,71 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-268 + * PLACE: overload-resolution, receivers -> paragraph 5 -> sentence 4 + * RELEVANT PLACES: overload-resolution, receivers -> paragraph 5 -> sentence 3 + * NUMBER: 1 + * DESCRIPTION: Superclass companion object receivers are prioritized according to the inheritance order + */ + + +fun box(): String { + val case0 =CaseBase0().case0() + val case1 =CaseBase1().case1() + val case2 =CaseBase2().case2() + if (case0 && case1 && case2) + return "OK" + return "NOK" +} + +class CaseBase2() : CaseBase1() { + + companion object foo { + var isCaseCompanionCalled = false + fun foo() { + isCaseCompanionCalled = true + } + } + + fun case2(): Boolean { + foo.foo() + val res = !isCaseBase0ReceiverCalled && !isCaseBaseReceiverCalled && isCaseCompanionCalled + isCaseCompanionCalled = false + return res + } +} + +open class CaseBase1 : CaseBase0() { + companion object foo { + var isCaseBaseReceiverCalled = false + fun foo() { + this.isCaseBaseReceiverCalled = true + } + } + + fun case1(): Boolean { + foo.foo() + val res = !isCaseBase0ReceiverCalled && CaseBase1.isCaseBaseReceiverCalled && !CaseBase2.isCaseCompanionCalled + isCaseBaseReceiverCalled = false + return res + } + +} + +open class CaseBase0 { + companion object foo { + var isCaseBase0ReceiverCalled = false + fun foo() { + this.isCaseBase0ReceiverCalled = true + } + } + + fun case0(): Boolean { + foo.foo() + val res = isCaseBase0ReceiverCalled && !CaseBase1.isCaseBaseReceiverCalled && !CaseBase2.isCaseCompanionCalled + isCaseBase0ReceiverCalled = false + return res + } +} diff --git a/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/testsMap.json b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/testsMap.json new file mode 100644 index 00000000000..7e22b25590d --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/testsMap.json @@ -0,0 +1,49 @@ +{ + "5": { + "pos": { + "2": [ + { + "specVersion": "0.1-268", + "casesNumber": 0, + "description": "implicit this receiver has higher priority than any companion object receiver", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-268", + "casesNumber": 0, + "description": "implicit this receiver has higher priority than any companion object receiver", + "unexpectedBehaviour": false + } + ], + "3": [ + { + "specVersion": "0.1-268", + "casesNumber": 0, + "description": "Current class companion object receiver has higher priority than any of the superclass companion objects;", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-268", + "casesNumber": 0, + "description": "Superclass companion object receivers are prioritized according to the inheritance order", + "path": "compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/4.1.kt", + "unexpectedBehaviour": false + }, + { + "specVersion": "0.1-268", + "casesNumber": 0, + "description": "Current class companion object receiver has higher priority than any of the superclass companion objects;", + "unexpectedBehaviour": false + } + ], + "4": [ + { + "specVersion": "0.1-268", + "casesNumber": 0, + "description": "Superclass companion object receivers are prioritized according to the inheritance order", + "unexpectedBehaviour": false + } + ] + } + } +} \ No newline at end of file diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java index 7120ae5b0d6..a4b12bbafc8 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/codegen/BlackBoxCodegenTestSpecGenerated.java @@ -3388,6 +3388,70 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes } } } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Receivers extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInReceivers() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class P_5 extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInP_5() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Pos extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + @TestMetadata("2.1.kt") + public void test2_1() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/2.1.kt"); + } + + @TestMetadata("2.2.kt") + public void test2_2() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/2.2.kt"); + } + + @TestMetadata("3.1.kt") + public void test3_1() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/3.1.kt"); + } + + @TestMetadata("3.2.kt") + public void test3_2() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/3.2.kt"); + } + + @TestMetadata("4.1.kt") + public void test4_1() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos/4.1.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/receivers/p-5/pos"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + } + } + } } @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/statements")