diff --git a/compiler/tests-spec/build.gradle.kts b/compiler/tests-spec/build.gradle.kts index 34ae43c99f4..707d1d6f8c9 100644 --- a/compiler/tests-spec/build.gradle.kts +++ b/compiler/tests-spec/build.gradle.kts @@ -29,6 +29,7 @@ val remoteRunTests by task { val includeTests = setOf( "checkers.DiagnosticsTestSpecGenerated\$NotLinked\$Contracts*", "checkers.DiagnosticsTestSpecGenerated\$NotLinked\$Annotations*", + "checkers.DiagnosticsTestSpecGenerated\$NotLinked\$Local_variables\$Type_parameters*", "codegen.BlackBoxCodegenTestSpecGenerated\$NotLinked\$Annotations\$Type_annotations*", "codegen.BlackBoxCodegenTestSpecGenerated\$NotLinked\$Objects\$Inheritance*" ) diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/local-variables/type-parameters/neg/1.kt b/compiler/tests-spec/testData/diagnostics/notLinked/local-variables/type-parameters/neg/1.kt new file mode 100644 index 00000000000..8b9de3de459 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/notLinked/local-variables/type-parameters/neg/1.kt @@ -0,0 +1,104 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (NEGATIVE) + * + * SECTIONS: local-variables, type-parameters + * NUMBER: 1 + * DESCRIPTION: Local variables with forbidden type parameters. + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-8341 + */ + +// TESTCASE NUMBER: 1 +fun case_1() { + val x1 = 1 + var x2 = 1 +} + +// TESTCASE NUMBER: 2 +fun case_2() { + val x1: Int = 1 + var x2: Int = 1 +} + +// TESTCASE NUMBER: 3 +fun case_3() { + val x1: Map = mapOf(1 to 1) + var x2: Map = mapOf(1 to 1) +} + +// TESTCASE NUMBER: 4 +fun case_4() { + val y1: Number where __UNRESOLVED__: __UNRESOLVED__ = 1 + var y2: Number where __UNRESOLVED__: __UNRESOLVED__ = 1 +} + +// TESTCASE NUMBER: 5 +fun case_5() { + val __UNRESOLVED__> x1: Map = mapOf(1 to 1) + var __UNRESOLVED__> x2: Map = mapOf(1 to 1) +} + +/* + * TESTCASE NUMBER: 6 + * UNEXPECTED BEHAVIOUR + */ +fun case_6() { + val __UNRESOLVED__> (x1, y1) = Pair(1, 2) + var __UNRESOLVED__> (x2, y2) = Pair(1, 2) +} + +/* + * TESTCASE NUMBER: 7 + * UNEXPECTED BEHAVIOUR + */ +fun case_7() { + val __UNRESOLVED__> (x1, y1) where __UNRESOLVED__: __UNRESOLVED__ = Pair(1, 2) + var __UNRESOLVED__> (x2, y2) where __UNRESOLVED__: __UNRESOLVED__ = Pair(1, 2) +} + +// TESTCASE NUMBER: 8 +fun case_8() { + val A, C : B, D : C, E : D> x1 = 1 + var A, C : B, D : C, E : D> x2 = 2 +} + +// TESTCASE NUMBER: 9 +fun case_9(y: Boolean?) = when (val x = y) { + true -> null + false -> null + null -> null +} + +// TESTCASE NUMBER: 10 +fun case_10(x: Boolean?) = when (val x where T: suspend () -> Unit, T: Boolean = x) { + true -> null + false -> null + null -> null +} + +// TESTCASE NUMBER: 11 +fun case_11() { + val x by lazy { 1 } + var x by lazy { 1 } +} + +// TESTCASE NUMBER: 12 +fun case_12() { + val __UNRESOLVED__> x: Int + var __UNRESOLVED__> x: Int +} + +// TESTCASE NUMBER: 13 +fun case_13() { + val __UNRESOLVED__> x: Int where __UNRESOLVED__: __UNRESOLVED__ + var __UNRESOLVED__> x: Int where __UNRESOLVED__: __UNRESOLVED__ +} + +// TESTCASE NUMBER: 14 +fun case_14() { + val T> x1 = 1 + var T> x2 = 1 +} diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestSpecGenerated.java b/compiler/tests-spec/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestSpecGenerated.java index 125d820bfb3..f3e5c2e0032 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestSpecGenerated.java +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestSpecGenerated.java @@ -2369,5 +2369,49 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { } } } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/notLinked/local-variables") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Local_variables extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInLocal_variables() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/notLinked/local-variables"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/notLinked/local-variables/type-parameters") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Type_parameters extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInType_parameters() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/notLinked/local-variables/type-parameters"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/notLinked/local-variables/type-parameters/neg") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Neg extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + @TestMetadata("1.kt") + public void test1() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/notLinked/local-variables/type-parameters/neg/1.kt"); + } + + public void testAllFilesPresentInNeg() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/notLinked/local-variables/type-parameters/neg"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + } + } + } } }