diff --git a/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/p-4/pos/1.1.kt b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/p-4/pos/1.1.kt new file mode 100644 index 00000000000..1edcbd4db01 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/p-4/pos/1.1.kt @@ -0,0 +1,37 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-268 + * PLACE: overload-resolution, building-the-overload-candidate-set-ocs, infix-function-call -> paragraph 4 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: infix calls for properties + */ + +class C() { + var isInvokeCalled = false + infix operator fun invoke(i: Int) { isInvokeCalled = true } //(1) +} + +class B() { + val memberValC + get() = c +} +val c = C() + +val B.extensionValC: C + get() = c + + +fun box(): String{ + val b = B() + b memberValC 3 //resolved to (1) o_O + if (b.memberValC.isInvokeCalled) { + c.isInvokeCalled = false + b extensionValC 4 //resolved to (1) o_O + if (b.extensionValC.isInvokeCalled) + return "OK" + } + return "NOK" +} diff --git a/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/testsMap.json b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/testsMap.json new file mode 100644 index 00000000000..1fc2d58a57f --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/testsMap.json @@ -0,0 +1,14 @@ +{ + "4": { + "pos": { + "1": [ + { + "specVersion": "0.1-268", + "casesNumber": 0, + "description": "infix calls for properties", + "unexpectedBehaviour": false + } + ] + } + } +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/1.kt b/compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/1.kt new file mode 100644 index 00000000000..51846063109 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/1.kt @@ -0,0 +1,33 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (POSITIVE) + * + * SECTIONS: overload-resolution, building-the-overload-candidate-set-ocs, infix-function-call + * NUMBER: 1 + * DESCRIPTION: Not null Smartcast doesn't work in case of property infix call + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-36786 + */ + +class C() { + infix operator fun invoke(i: Int) { } //(1) +} + +class B(val memberValCNull: C? = null) { + infix fun bar(i: Int) {} +} + +// TESTCASE NUMBER: 1 +fun case1() { + val b: B = B() +// b memberValCNull 1 //nok (UNSAFE_INFIX_CALL) +// b.memberValCNull.invoke(1) //nok (UNSAFE_CALL) + + if (b.memberValCNull != null) { + b memberValCNull 1 //nok (UNSAFE_INFIX_CALL) !!!! + b.memberValCNull.invoke(2) //ok + b.memberValCNull(3) //nok (UNSAFE_CALL) !!! + } +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/2.kt b/compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/2.kt new file mode 100644 index 00000000000..ddb6169c93d --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/2.kt @@ -0,0 +1,33 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (POSITIVE) + * + * SECTIONS: overload-resolution, building-the-overload-candidate-set-ocs, infix-function-call + * NUMBER: 2 + * DESCRIPTION: is-check Smartcast doesn't work in case of property infix call + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-36786 + */ + +class B(val memberVal: Any) +class C() { + infix operator fun invoke(i: Int) { } //(1) +} +// TESTCASE NUMBER: 1 +fun case1() { + val b: B = B(C()) + b memberVal 1 //nok UNRESOLVED_REFERENCE + b.memberVal.invoke(2) //nok UNRESOLVED_REFERENCE + b.memberVal(1) //nok FUNCTION_EXPECTED + + if (b.memberVal is C) { + + b memberVal 1 //nok UNRESOLVED_REFERENCE !!!! + b.memberVal.invoke(1) //ok + + b.memberVal(1) //nok FUNCTION_EXPECTED !!! + (b.memberVal)(1) //ok + } +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/3.kt b/compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/3.kt new file mode 100644 index 00000000000..182b4e64683 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/3.kt @@ -0,0 +1,34 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (POSITIVE) + * + * SECTIONS: overload-resolution, building-the-overload-candidate-set-ocs, infix-function-call + * NUMBER: 3 + * DESCRIPTION: "Unsafe" cast doesn't work in case of property infix call + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-36786 + */ + +class B(val memberVal: Any) +class C() { + infix operator fun invoke(i: Int) { } //(1) +} + +// TESTCASE NUMBER: 1 +fun case1() { + val b: B = B(C()) + b memberVal 1 //nok UNRESOLVED_REFERENCE + b.memberVal.invoke(2) //nok UNRESOLVED_REFERENCE + b.memberVal(1) //nok FUNCTION_EXPECTED + + b.memberVal as C + + b memberVal 1 //nok UNRESOLVED_REFERENCE !!!! + b.memberVal.invoke(1) //ok + + b.memberVal(1) //nok FUNCTION_EXPECTED !!! + (b.memberVal)(1) //ok + +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/4.kt b/compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/4.kt new file mode 100644 index 00000000000..6dd2a78d869 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/4.kt @@ -0,0 +1,109 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (POSITIVE) + * + * SECTIONS: overload-resolution, building-the-overload-candidate-set-ocs, infix-function-call + * NUMBER: 4 + * DESCRIPTION: Local extension infix extension callables + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-36786 + */ + + +// TESTCASE NUMBER: 1, 2 +// FILE: infixLib.kt +package libPackage + +class C() { + infix operator fun invoke(i: Int) {} +} + +class B() { + val barC: C = TODO() + val B.barC: C + get() = TODO() + + infix fun fooC(i: Int) = {} + infix fun B.fooC(i: Int) = + {} +} + +infix fun B.fooC(i: Int) = {} +val B.barC: C +get() = TODO() + + +// FILE: TestCase1.kt +/* + * TESTCASE NUMBER: 1 + * NOTE: should be resolved to member properties, others should be shadowed by member function + */ +package testPackInfix +import libPackage.C +import libPackage.B +import libPackage.* + + +fun case1() { + class Case() { + val B.barC: C + get() = TODO() + + fun case() { + val b = B() + b fooC 3 + b barC 3 + } + } + + fun case() { + val b = B() + b fooC 3 + b barC 3 + } +} + +// FILE: TestCase2.kt +/* + * TESTCASE NUMBER: 2 + * NOTE: should be resolved to member properties, others should be shadowed by member property with invoke or by member function + */ +package testPackInfix +import libPackage.C +import libPackage.B +import libPackage.* +import libPackage.fooC +import libPackage.barC + +/*should be shadowed by member function*/ +infix fun B.fooC(i: Int) = {} +/*should be shadowed by member property with invoke*/ +infix fun B.barC(i: Int) = {} +/*should be shadowed by member property*/ +val B.barC: C +get() = TODO() + +fun case2() { + class Case() { + /*should be shadowed by member property*/ + val B.barC: C + get() = TODO() + /*should be shadowed by member property with invoke*/ + infix fun B.barC(i: Int) = {} + /*should be shadowed by member function*/ + infix fun B.fooC(i: Int) = {} + fun case() { + val b = B() + b fooC 3 + b barC 3 + } + } + + fun case() { + val b = B() + b fooC 3 + b barC 3 + } +} \ 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 db91824df27..09feb008165 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 @@ -5931,5 +5931,77 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { } } } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Overload_resolution extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInOverload_resolution() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Building_the_overload_candidate_set_ocs extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInBuilding_the_overload_candidate_set_ocs() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Infix_function_call extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInInfix_function_call() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/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.kt") + public void test1() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/1.kt"); + } + + @TestMetadata("2.kt") + public void test2() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/2.kt"); + } + + @TestMetadata("3.kt") + public void test3() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/3.kt"); + } + + @TestMetadata("4.kt") + public void test4() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos/4.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/notLinked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/pos"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + } + } + } + } } } 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 a4b12bbafc8..72c0b5a6a59 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 @@ -3305,6 +3305,63 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution"), Pattern.compile("^(.+)\\.kt$"), null, true); } + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Building_the_overload_candidate_set_ocs extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInBuilding_the_overload_candidate_set_ocs() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Infix_function_call extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInInfix_function_call() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/p-4") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class P_4 extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInP_4() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/p-4"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/p-4/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("1.1.kt") + public void test1_1() throws Exception { + runTest("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/p-4/pos/1.1.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/building-the-overload-candidate-set-ocs/infix-function-call/p-4/pos"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + } + } + } + } + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/overload-resolution/callables-and-invoke-convention") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)