diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression/p-2/pos/1.1.kt b/compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression/p-2/pos/1.1.kt new file mode 100644 index 00000000000..a7dc42df481 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression/p-2/pos/1.1.kt @@ -0,0 +1,33 @@ +// WITH_RUNTIME + +/* + * KOTLIN CODEGEN BOX SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-218 + * PLACE: expressions, range-expression -> paragraph 2 -> sentence 1 + * RELEVANT PLACES: expressions, range-expression -> paragraph 1 -> sentence 1 + * expressions, range-expression -> paragraph 1 -> sentence 2 + * expressions, range-expression -> paragraph 3 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: A..B is exactly the same as A.rangeTo(B) + */ + +class A(val a: Int) { + var isRangeToCalled = false + operator fun rangeTo(o: A): MutableList { + isRangeToCalled = true + val x: MutableList = mutableListOf() + for (i in a..o.a) + x.add(i) + return x + } +} + +fun box(): String { + val a1 = A(0) + val a2 = A(5) + val x = a1..a2 + if (a1.isRangeToCalled && x is MutableList) + return "OK" + return "NOK" +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression/testsMap.json b/compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression/testsMap.json new file mode 100644 index 00000000000..e784a7204e8 --- /dev/null +++ b/compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression/testsMap.json @@ -0,0 +1,27 @@ +{ + "2": { + "pos": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "A..B is exactly the same as A.rangeTo(B)", + "unexpectedBehaviour": false + } + ] + } + }, + "1": { + "pos": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 0, + "description": "A..B is exactly the same as A.rangeTo(B)", + "path": "compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression/p-2/pos/1.1.kt", + "unexpectedBehaviour": false + } + ] + } + } +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression/p-4/pos/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression/p-4/pos/1.1.kt new file mode 100644 index 00000000000..2f17c17fc9f --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression/p-4/pos/1.1.kt @@ -0,0 +1,41 @@ +// !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-218 + * PLACE: expressions, range-expression -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: expressions, range-expression -> paragraph 4 -> sentence 2 + * NUMBER: 1 + * DESCRIPTION: The return type of range operator is not restricted. + * HELPERS: checkType + */ + + +// TESTCASE NUMBER: 1 +class Case1() { + operator fun rangeTo(o: Case1): Nothing?{ + TODO() + } +} +fun case1() { + val x = Case1() .. Case1() + x + x checkType { check() } +} + + +// TESTCASE NUMBER: 2 +class Case2() { + operator fun rangeTo(o: Case2): Any?{ + TODO() + } +} +fun case2() { + val x = Case2() .. Case2() + x + x checkType { check() } +} + diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression/testsMap.json b/compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression/testsMap.json new file mode 100644 index 00000000000..9ad5abea0ae --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression/testsMap.json @@ -0,0 +1,23 @@ +{ + "4": { + "pos": { + "1": [ + { + "specVersion": "0.1-218", + "casesNumber": 2, + "description": "The return type of range operator is not restricted.", + "unexpectedBehaviour": false + } + ], + "2": [ + { + "specVersion": "0.1-218", + "casesNumber": 2, + "description": "The return type of range operator is not restricted.", + "path": "compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression/p-4/pos/1.1.kt", + "unexpectedBehaviour": false + } + ] + } + } +} \ 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 b84962add91..2276f2e7d64 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 @@ -1992,6 +1992,50 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { } } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Range_expression extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInRange_expression() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression/p-4") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class P_4 extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInP_4() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression/p-4"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression/p-4/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/expressions/range-expression/p-4/pos/1.1.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/expressions/range-expression/p-4/pos"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + } + } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) 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 d0010b731be..7ab836eedeb 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 @@ -1543,6 +1543,50 @@ public class BlackBoxCodegenTestSpecGenerated extends AbstractBlackBoxCodegenTes } } + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Range_expression extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInRange_expression() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression/p-2") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class P_2 extends AbstractBlackBoxCodegenTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInP_2() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression/p-2"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression/p-2/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/expressions/range-expression/p-2/pos/1.1.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/codegen/box/linked/expressions/range-expression/p-2/pos"), Pattern.compile("^(.+)\\.kt$"), true); + } + } + } + } + @TestMetadata("compiler/tests-spec/testData/codegen/box/linked/expressions/try-expression") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)