diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 13876ed5f08..330e2a0e070 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -28236,6 +28236,96 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/testsWithJava15") + @TestDataPath("$PROJECT_ROOT") + public class TestsWithJava15 extends AbstractFirDiagnosticTest { + @Test + public void testAllFilesPresentInTestsWithJava15() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/testsWithJava15"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord") + @TestDataPath("$PROJECT_ROOT") + public class JvmRecord extends AbstractFirDiagnosticTest { + @Test + public void testAllFilesPresentInJvmRecord() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("diagnostics.kt") + public void testDiagnostics() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/diagnostics.kt"); + } + + @Test + @TestMetadata("disabledFeature.kt") + public void testDisabledFeature() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/disabledFeature.kt"); + } + + @Test + @TestMetadata("irrelevantFields.kt") + public void testIrrelevantFields() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/irrelevantFields.kt"); + } + + @Test + @TestMetadata("jvmRecordDescriptorStructure.kt") + public void testJvmRecordDescriptorStructure() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.kt"); + } + + @Test + @TestMetadata("simpleRecords.kt") + public void testSimpleRecords() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/simpleRecords.kt"); + } + + @Test + @TestMetadata("supertypesCheck.kt") + public void testSupertypesCheck() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/supertypesCheck.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses") + @TestDataPath("$PROJECT_ROOT") + public class SealedClasses extends AbstractFirDiagnosticTest { + @Test + public void testAllFilesPresentInSealedClasses() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("javaSealedClassExhaustiveness.kt") + public void testJavaSealedClassExhaustiveness() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedClassExhaustiveness.kt"); + } + + @Test + @TestMetadata("javaSealedInterfaceExhaustiveness.kt") + public void testJavaSealedInterfaceExhaustiveness() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedInterfaceExhaustiveness.kt"); + } + + @Test + @TestMetadata("kotlinInheritsJavaClass.kt") + public void testKotlinInheritsJavaClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaClass.kt"); + } + + @Test + @TestMetadata("kotlinInheritsJavaInterface.kt") + public void testKotlinInheritsJavaInterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaInterface.kt"); + } + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/thisAndSuper") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt index 873a284b96a..b030aa23494 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt @@ -67,6 +67,7 @@ class LanguageVersionSettingsBuilder { analysisFlag(JvmAnalysisFlags.jvmDefaultMode, directives.singleOrZeroValue(LanguageSettingsDirectives.JVM_DEFAULT_MODE)), analysisFlag(JvmAnalysisFlags.inheritMultifileParts, trueOrNull(LanguageSettingsDirectives.INHERIT_MULTIFILE_PARTS in directives)), analysisFlag(JvmAnalysisFlags.sanitizeParentheses, trueOrNull(LanguageSettingsDirectives.SANITIZE_PARENTHESES in directives)), + analysisFlag(JvmAnalysisFlags.enableJvmPreview, trueOrNull(LanguageSettingsDirectives.ENABLE_JVM_PREVIEW in directives)), analysisFlag(AnalysisFlags.explicitApiVersion, trueOrNull(apiVersion != null)), ) diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/LanguageSettingsDirectives.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/LanguageSettingsDirectives.kt index 2abf2bb179d..36e21b29d5d 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/LanguageSettingsDirectives.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/LanguageSettingsDirectives.kt @@ -67,6 +67,8 @@ object LanguageSettingsDirectives : SimpleDirectivesContainer() { description = "Enables corresponding analysis flag (JvmAnalysisFlags.sanitizeParentheses)" ) + val ENABLE_JVM_PREVIEW by directive("Enable JVM preview features") + // --------------------- Utils --------------------- fun parseApiVersion(versionString: String): ApiVersion = when (versionString) { diff --git a/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/diagnostics.fir.kt b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/diagnostics.fir.kt new file mode 100644 index 00000000000..c346a1a7182 --- /dev/null +++ b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/diagnostics.fir.kt @@ -0,0 +1,56 @@ +// !API_VERSION: 1.5 +// !LANGUAGE: +JvmRecordSupport +// SKIP_TXT +// JVM_TARGET: 15 +// ENABLE_JVM_PREVIEW + +@JvmRecord +class A0 + +@JvmRecord +class A1 { + constructor() +} + +@JvmRecord +class A2() + +@JvmRecord +class A3(name: String) + +@JvmRecord +class A4(var name: String) + +@JvmRecord +class A5(vararg val name: String, y: Int) + +@JvmRecord +open class A6(val x: String) + +@JvmRecord +abstract class A7(val x: String) + +@JvmRecord +sealed class A8(val x: String) + +@JvmRecord +enum class A9(val x: String) { + X(""); +} + +@JvmRecord +class A10( + val x: String, + val y: Int, + vararg val z: Double, +) + +fun main() { + @JvmRecord + class Local +} + +class Outer { + @JvmRecord + inner class Inner(val name: String) +} diff --git a/compiler/testData/diagnostics/testsWithJava15/jvmRecord/diagnostics.kt b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/diagnostics.kt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/jvmRecord/diagnostics.kt rename to compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/diagnostics.kt diff --git a/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/disabledFeature.fir.kt b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/disabledFeature.fir.kt new file mode 100644 index 00000000000..e5eae937740 --- /dev/null +++ b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/disabledFeature.fir.kt @@ -0,0 +1,23 @@ +// !API_VERSION: 1.5 +// !LANGUAGE: -JvmRecordSupport +// SKIP_TXT +// FILE: JRecord.java +public record JRecord(int x, CharSequence y) {} +// FILE: main.kt + +@JvmRecord +class MyRec( + val x: String, + val y: Int, + vararg val z: Double, +) + +fun foo(jr: JRecord) { + JRecord(1, "") + + jr.x() + jr.y() + + jr.x + jr.y +} diff --git a/compiler/testData/diagnostics/testsWithJava15/jvmRecord/disabledFeature.kt b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/disabledFeature.kt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/jvmRecord/disabledFeature.kt rename to compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/disabledFeature.kt diff --git a/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/irrelevantFields.fir.kt b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/irrelevantFields.fir.kt new file mode 100644 index 00000000000..22af17371a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/irrelevantFields.fir.kt @@ -0,0 +1,43 @@ +// !API_VERSION: 1.5 +// !LANGUAGE: +JvmRecordSupport +// SKIP_TXT +// JVM_TARGET: 15 +// ENABLE_JVM_PREVIEW + +interface I + +val i: I = object : I {} + +@JvmRecord +data class MyRec1(val name: String) : I by i + +@JvmRecord +data class MyRec2(val name: String) { + val x: Int = 0 +} + +@JvmRecord +data class MyRec3(val name: String) { + val y: String + get() = field + "1" + + init { + y = "" + } +} + +@JvmRecord +data class MyRec4(val name: String) { + val z: Int by lazy { 1 } +} + +@JvmRecord +data class MyRec5(val name: String) { + val w: String get() = name + "1" +} + + + + + + diff --git a/compiler/testData/diagnostics/testsWithJava15/jvmRecord/irrelevantFields.kt b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/irrelevantFields.kt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/jvmRecord/irrelevantFields.kt rename to compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/irrelevantFields.kt diff --git a/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.fir.kt b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.fir.kt new file mode 100644 index 00000000000..6d691424021 --- /dev/null +++ b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.fir.kt @@ -0,0 +1,14 @@ +// !API_VERSION: 1.5 +// !LANGUAGE: +JvmRecordSupport +// JVM_TARGET: 15 +// ENABLE_JVM_PREVIEW + +@JvmRecord +class BasicRecord(val x: String) + +@JvmRecord +data class BasicDataRecord(val x: String) + +@JvmRecord +class BasicRecordWithSuperClass(val x: String) : Record() + diff --git a/compiler/testData/diagnostics/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.kt b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.kt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.kt rename to compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.kt diff --git a/compiler/testData/diagnostics/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.txt b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.txt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.txt rename to compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.txt diff --git a/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/simpleRecords.fir.kt b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/simpleRecords.fir.kt new file mode 100644 index 00000000000..58fb8a59523 --- /dev/null +++ b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/simpleRecords.fir.kt @@ -0,0 +1,18 @@ +// !API_VERSION: 1.5 +// !LANGUAGE: +JvmRecordSupport +// FILE: MyRecord.java +public record MyRecord(int x, CharSequence y) { + +} + +// FILE: main.kt + +fun foo(mr: MyRecord) { + MyRecord(1, "") + + mr.x() + mr.y() + + mr.x + mr.y +} diff --git a/compiler/testData/diagnostics/testsWithJava15/jvmRecord/simpleRecords.kt b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/simpleRecords.kt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/jvmRecord/simpleRecords.kt rename to compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/simpleRecords.kt diff --git a/compiler/testData/diagnostics/testsWithJava15/jvmRecord/simpleRecords.txt b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/simpleRecords.txt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/jvmRecord/simpleRecords.txt rename to compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/simpleRecords.txt diff --git a/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/supertypesCheck.fir.kt b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/supertypesCheck.fir.kt new file mode 100644 index 00000000000..6624134fec9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/supertypesCheck.fir.kt @@ -0,0 +1,26 @@ +// !API_VERSION: 1.5 +// !LANGUAGE: +JvmRecordSupport +// JVM_TARGET: 15 +// ENABLE_JVM_PREVIEW + +abstract class Abstract +interface I + +@JvmRecord +data class A1(val x: String) : Abstract(), I + +@JvmRecord +data class A2(val x: String) : Any(), I + +@JvmRecord +data class A3(val x: String) : Record(), I + +@JvmRecord +data class A4(val x: String) : java.lang.Record(), I + +@JvmRecord +data class A5(val x: String) : I + +data class A6(val x: String) : Record(), I + +data class A7(val x: String) : java.lang.Record(), I diff --git a/compiler/testData/diagnostics/testsWithJava15/jvmRecord/supertypesCheck.kt b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/supertypesCheck.kt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/jvmRecord/supertypesCheck.kt rename to compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/supertypesCheck.kt diff --git a/compiler/testData/diagnostics/testsWithJava15/jvmRecord/supertypesCheck.txt b/compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/supertypesCheck.txt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/jvmRecord/supertypesCheck.txt rename to compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/supertypesCheck.txt diff --git a/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedClassExhaustiveness.fir.kt b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedClassExhaustiveness.fir.kt new file mode 100644 index 00000000000..cce64dd75a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedClassExhaustiveness.fir.kt @@ -0,0 +1,44 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// ISSUE: KT-41215, KT-43551 + +// FILE: Base.java +public sealed class Base permits A, B {} + +// FILE: A.java +public final class A extends Base {} + +// FILE: B.java +public sealed class B extends Base permits B.C, B.D { + public static final class C implements B {} + + public static non-sealed class D extends B {} +} + +// FILE: main.kt +fun test_ok_1(base: Base) { + val x = when (base) { + is A -> 1 + is B -> 2 + } +} + +fun test_ok_2(base: Base) { + val x = when (base) { + is A -> 1 + is B.C -> 2 + is B.D -> 3 + } +} + +fun test_error_1(base: Base) { + val x = when (base) { + is A -> 1 + } +} + +fun test_error_2(base: Base) { + val x = when (base) { + is A -> 1 + is B.C -> 2 + } +} diff --git a/compiler/testData/diagnostics/testsWithJava15/sealedClasses/javaSealedClassExhaustiveness.kt b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedClassExhaustiveness.kt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/sealedClasses/javaSealedClassExhaustiveness.kt rename to compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedClassExhaustiveness.kt diff --git a/compiler/testData/diagnostics/testsWithJava15/sealedClasses/javaSealedClassExhaustiveness.txt b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedClassExhaustiveness.txt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/sealedClasses/javaSealedClassExhaustiveness.txt rename to compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedClassExhaustiveness.txt diff --git a/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedInterfaceExhaustiveness.fir.kt b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedInterfaceExhaustiveness.fir.kt new file mode 100644 index 00000000000..3e478edc7ec --- /dev/null +++ b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedInterfaceExhaustiveness.fir.kt @@ -0,0 +1,64 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// ISSUE: KT-41215, KT-43551 + +// FILE: Base.java +public sealed interface Base permits A, B, E {} + +// FILE: A.java +public non-sealed interface A extends Base {} + +// FILE: B.java +public sealed interface B extends Base permits B.C, B.D { + public static final class C implements B {} + + public static non-sealed interface D extends B {} +} + +// FILE: E.java +public enum E implements Base { + First, Second +} + +// FILE: main.kt +fun test_ok_1(base: Base) { + val x = when (base) { + is A -> 1 + is B -> 2 + is E -> 3 + } +} + +fun test_ok_2(base: Base) { + val x = when (base) { + is A -> 1 + is B.C -> 2 + is B.D -> 3 + E.First -> 4 + E.Second -> 5 + } +} + +fun test_error_1(base: Base) { + val x = when (base) { + is A -> 1 + is B -> 2 + } +} + +fun test_error_2(base: Base) { + val x = when (base) { + is A -> 1 + is B.C -> 2 + is B.D -> 3 + E.Second -> 5 + } +} + +fun test_error_3(base: Base) { + val x = when (base) { + is A -> 1 + is B.C -> 2 + E.First -> 4 + E.Second -> 5 + } +} diff --git a/compiler/testData/diagnostics/testsWithJava15/sealedClasses/javaSealedInterfaceExhaustiveness.kt b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedInterfaceExhaustiveness.kt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/sealedClasses/javaSealedInterfaceExhaustiveness.kt rename to compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedInterfaceExhaustiveness.kt diff --git a/compiler/testData/diagnostics/testsWithJava15/sealedClasses/javaSealedInterfaceExhaustiveness.txt b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedInterfaceExhaustiveness.txt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/sealedClasses/javaSealedInterfaceExhaustiveness.txt rename to compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedInterfaceExhaustiveness.txt diff --git a/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaClass.fir.kt b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaClass.fir.kt new file mode 100644 index 00000000000..2cce51631b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaClass.fir.kt @@ -0,0 +1,11 @@ +// ISSUE: KT-41215 + +// FILE: Base.java +public sealed class Base permits A, B {} + +// FILE: A.java +public final class A extends Base {} + +// FILE: B.kt + +class B : Base() diff --git a/compiler/testData/diagnostics/testsWithJava15/sealedClasses/kotlinInheritsJavaClass.kt b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaClass.kt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/sealedClasses/kotlinInheritsJavaClass.kt rename to compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaClass.kt diff --git a/compiler/testData/diagnostics/testsWithJava15/sealedClasses/kotlinInheritsJavaClass.txt b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaClass.txt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/sealedClasses/kotlinInheritsJavaClass.txt rename to compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaClass.txt diff --git a/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaInterface.fir.kt b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaInterface.fir.kt new file mode 100644 index 00000000000..fd2cf989bd4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaInterface.fir.kt @@ -0,0 +1,11 @@ +// ISSUE: KT-41215 + +// FILE: Base.java +public sealed interface Base permits A, B {} + +// FILE: A.java +public final class A extends Base {} + +// FILE: B.kt + +class B : Base diff --git a/compiler/testData/diagnostics/testsWithJava15/sealedClasses/kotlinInheritsJavaInterface.kt b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaInterface.kt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/sealedClasses/kotlinInheritsJavaInterface.kt rename to compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaInterface.kt diff --git a/compiler/testData/diagnostics/testsWithJava15/sealedClasses/kotlinInheritsJavaInterface.txt b/compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaInterface.txt similarity index 100% rename from compiler/testData/diagnostics/testsWithJava15/sealedClasses/kotlinInheritsJavaInterface.txt rename to compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaInterface.txt diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 333d8aaad45..a6d37f4ec75 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -28332,6 +28332,96 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/testsWithJava15") + @TestDataPath("$PROJECT_ROOT") + public class TestsWithJava15 extends AbstractDiagnosticTest { + @Test + public void testAllFilesPresentInTestsWithJava15() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/testsWithJava15"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord") + @TestDataPath("$PROJECT_ROOT") + public class JvmRecord extends AbstractDiagnosticTest { + @Test + public void testAllFilesPresentInJvmRecord() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("diagnostics.kt") + public void testDiagnostics() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/diagnostics.kt"); + } + + @Test + @TestMetadata("disabledFeature.kt") + public void testDisabledFeature() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/disabledFeature.kt"); + } + + @Test + @TestMetadata("irrelevantFields.kt") + public void testIrrelevantFields() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/irrelevantFields.kt"); + } + + @Test + @TestMetadata("jvmRecordDescriptorStructure.kt") + public void testJvmRecordDescriptorStructure() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.kt"); + } + + @Test + @TestMetadata("simpleRecords.kt") + public void testSimpleRecords() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/simpleRecords.kt"); + } + + @Test + @TestMetadata("supertypesCheck.kt") + public void testSupertypesCheck() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/jvmRecord/supertypesCheck.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses") + @TestDataPath("$PROJECT_ROOT") + public class SealedClasses extends AbstractDiagnosticTest { + @Test + public void testAllFilesPresentInSealedClasses() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("javaSealedClassExhaustiveness.kt") + public void testJavaSealedClassExhaustiveness() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedClassExhaustiveness.kt"); + } + + @Test + @TestMetadata("javaSealedInterfaceExhaustiveness.kt") + public void testJavaSealedInterfaceExhaustiveness() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/javaSealedInterfaceExhaustiveness.kt"); + } + + @Test + @TestMetadata("kotlinInheritsJavaClass.kt") + public void testKotlinInheritsJavaClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaClass.kt"); + } + + @Test + @TestMetadata("kotlinInheritsJavaInterface.kt") + public void testKotlinInheritsJavaInterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/testsWithJava15/sealedClasses/kotlinInheritsJavaInterface.kt"); + } + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/thisAndSuper") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticTest.kt index e3db8408a71..cf032ff4adc 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractDiagnosticTest.kt @@ -7,10 +7,12 @@ package org.jetbrains.kotlin.test.runners import org.jetbrains.kotlin.config.ExplicitApiMode import org.jetbrains.kotlin.platform.jvm.JvmPlatforms +import org.jetbrains.kotlin.test.TestJdkKind import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder -import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.REPORT_JVM_DIAGNOSTICS_ON_FRONTEND +import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.JDK_KIND import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.USE_PSI_CLASS_FILES_READING +import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.WITH_REFLECT import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.WITH_STDLIB import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.EXPLICIT_API_MODE import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.USE_EXPERIMENTAL @@ -80,5 +82,13 @@ abstract class AbstractDiagnosticTest : AbstractKotlinCompilerTest() { +WITH_STDLIB } } + + forTestsMatching("compiler/testData/diagnostics/tests/testsWithJava15/*") { + defaultDirectives { + JDK_KIND with TestJdkKind.FULL_JDK_15 + +WITH_STDLIB + +WITH_REFLECT + } + } } } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractFirDiagnosticTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractFirDiagnosticTest.kt index 374bcd86d32..fa45603261a 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractFirDiagnosticTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractFirDiagnosticTest.kt @@ -6,15 +6,14 @@ package org.jetbrains.kotlin.test.runners import org.jetbrains.kotlin.platform.jvm.JvmPlatforms +import org.jetbrains.kotlin.test.TestJdkKind import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder -import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.COMPARE_WITH_LIGHT_TREE import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.FIR_DUMP import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.USE_LIGHT_TREE import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.WITH_EXTENDED_CHECKERS import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.WITH_STDLIB -import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives import org.jetbrains.kotlin.test.frontend.fir.FirFailingTestSuppressor import org.jetbrains.kotlin.test.frontend.fir.FirFrontendFacade import org.jetbrains.kotlin.test.frontend.fir.handlers.* @@ -82,6 +81,14 @@ abstract class AbstractFirDiagnosticTest : AbstractKotlinCompilerTest() { +WITH_EXTENDED_CHECKERS } } + + forTestsMatching("compiler/testData/diagnostics/tests/testsWithJava15/*") { + defaultDirectives { + JvmEnvironmentConfigurationDirectives.JDK_KIND with TestJdkKind.FULL_JDK_15 + +WITH_STDLIB + +JvmEnvironmentConfigurationDirectives.WITH_REFLECT + } + } } } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JvmEnvironmentConfigurator.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JvmEnvironmentConfigurator.kt index bc7c0e36656..e40acf9035b 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JvmEnvironmentConfigurator.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JvmEnvironmentConfigurator.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.test.ConfigurationKind import org.jetbrains.kotlin.test.TestJdkKind import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives +import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives import org.jetbrains.kotlin.test.directives.model.DirectivesContainer import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives import org.jetbrains.kotlin.test.model.BackendKinds @@ -62,6 +63,9 @@ class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfig TestJdkKind.FULL_JDK_9 -> { configuration.put(JVMConfigurationKeys.JDK_HOME, KtTestUtil.getJdk9Home()) } + TestJdkKind.FULL_JDK_15 -> { + configuration.put(JVMConfigurationKeys.JDK_HOME, KtTestUtil.getJdk15Home()) + } TestJdkKind.FULL_JDK -> { if (SystemInfo.IS_AT_LEAST_JAVA9) { configuration.put(JVMConfigurationKeys.JDK_HOME, File(System.getProperty("java.home"))) @@ -96,6 +100,10 @@ class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfig configuration.addJvmClasspathRoot(ForTestCompileRuntime.androidAnnotationsForTests()) } + if (LanguageSettingsDirectives.ENABLE_JVM_PREVIEW in module.directives) { + configuration.put(JVMConfigurationKeys.ENABLE_JVM_PREVIEW, true) + } + val isIr = module.backendKind == BackendKinds.IrBackend configuration.put(JVMConfigurationKeys.IR, isIr) diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsWithJdk15Test.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsWithJdk15Test.kt deleted file mode 100644 index 186b4b836d9..00000000000 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsWithJdk15Test.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.kotlin.checkers - -import org.jetbrains.kotlin.test.ConfigurationKind -import org.jetbrains.kotlin.test.TestJdkKind - -abstract class AbstractDiagnosticsWithJdk15Test : AbstractDiagnosticsTest() { - - override fun getTestJdkKind(files: List): TestJdkKind { - return TestJdkKind.FULL_JDK_15 - } - - override fun extractConfigurationKind(files: List): ConfigurationKind { - return ConfigurationKind.ALL - } -} diff --git a/compiler/tests-for-compiler-generator/tests/org/jetbrains/kotlin/test/generators/GenerateJUnit3CompilerTests.kt b/compiler/tests-for-compiler-generator/tests/org/jetbrains/kotlin/test/generators/GenerateJUnit3CompilerTests.kt index b73af3237a4..5d4343d3f20 100644 --- a/compiler/tests-for-compiler-generator/tests/org/jetbrains/kotlin/test/generators/GenerateJUnit3CompilerTests.kt +++ b/compiler/tests-for-compiler-generator/tests/org/jetbrains/kotlin/test/generators/GenerateJUnit3CompilerTests.kt @@ -69,10 +69,6 @@ fun generateJUnit3CompilerTests(args: Array) { model("diagnostics/testsWithJsStdLibAndBackendCompilation") } - testClass { - model("diagnostics/testsWithJava15") - } - testClass { model("multiplatform", extension = null, recursive = true, excludeParentDirs = true) } diff --git a/compiler/tests-gen/org/jetbrains/kotlin/checkers/DiagnosticsWithJdk15TestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/checkers/DiagnosticsWithJdk15TestGenerated.java deleted file mode 100644 index 275adc5c870..00000000000 --- a/compiler/tests-gen/org/jetbrains/kotlin/checkers/DiagnosticsWithJdk15TestGenerated.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.checkers; - -import com.intellij.testFramework.TestDataPath; -import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.util.KtTestUtil; -import org.jetbrains.kotlin.test.TestMetadata; -import org.junit.runner.RunWith; - -import java.io.File; -import java.util.regex.Pattern; - -/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ -@SuppressWarnings("all") -@TestMetadata("compiler/testData/diagnostics/testsWithJava15") -@TestDataPath("$PROJECT_ROOT") -@RunWith(JUnit3RunnerWithInners.class) -public class DiagnosticsWithJdk15TestGenerated extends AbstractDiagnosticsWithJdk15Test { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - - public void testAllFilesPresentInTestsWithJava15() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithJava15"), Pattern.compile("^(.+)\\.kt$"), null, true); - } - - @TestMetadata("compiler/testData/diagnostics/testsWithJava15/jvmRecord") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class JvmRecord extends AbstractDiagnosticsWithJdk15Test { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - - public void testAllFilesPresentInJvmRecord() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithJava15/jvmRecord"), Pattern.compile("^(.+)\\.kt$"), null, true); - } - - @TestMetadata("diagnostics.kt") - public void testDiagnostics() throws Exception { - runTest("compiler/testData/diagnostics/testsWithJava15/jvmRecord/diagnostics.kt"); - } - - @TestMetadata("disabledFeature.kt") - public void testDisabledFeature() throws Exception { - runTest("compiler/testData/diagnostics/testsWithJava15/jvmRecord/disabledFeature.kt"); - } - - @TestMetadata("irrelevantFields.kt") - public void testIrrelevantFields() throws Exception { - runTest("compiler/testData/diagnostics/testsWithJava15/jvmRecord/irrelevantFields.kt"); - } - - @TestMetadata("jvmRecordDescriptorStructure.kt") - public void testJvmRecordDescriptorStructure() throws Exception { - runTest("compiler/testData/diagnostics/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.kt"); - } - - @TestMetadata("simpleRecords.kt") - public void testSimpleRecords() throws Exception { - runTest("compiler/testData/diagnostics/testsWithJava15/jvmRecord/simpleRecords.kt"); - } - - @TestMetadata("supertypesCheck.kt") - public void testSupertypesCheck() throws Exception { - runTest("compiler/testData/diagnostics/testsWithJava15/jvmRecord/supertypesCheck.kt"); - } - } - - @TestMetadata("compiler/testData/diagnostics/testsWithJava15/sealedClasses") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class SealedClasses extends AbstractDiagnosticsWithJdk15Test { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - - public void testAllFilesPresentInSealedClasses() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithJava15/sealedClasses"), Pattern.compile("^(.+)\\.kt$"), null, true); - } - - @TestMetadata("javaSealedClassExhaustiveness.kt") - public void testJavaSealedClassExhaustiveness() throws Exception { - runTest("compiler/testData/diagnostics/testsWithJava15/sealedClasses/javaSealedClassExhaustiveness.kt"); - } - - @TestMetadata("javaSealedInterfaceExhaustiveness.kt") - public void testJavaSealedInterfaceExhaustiveness() throws Exception { - runTest("compiler/testData/diagnostics/testsWithJava15/sealedClasses/javaSealedInterfaceExhaustiveness.kt"); - } - - @TestMetadata("kotlinInheritsJavaClass.kt") - public void testKotlinInheritsJavaClass() throws Exception { - runTest("compiler/testData/diagnostics/testsWithJava15/sealedClasses/kotlinInheritsJavaClass.kt"); - } - - @TestMetadata("kotlinInheritsJavaInterface.kt") - public void testKotlinInheritsJavaInterface() throws Exception { - runTest("compiler/testData/diagnostics/testsWithJava15/sealedClasses/kotlinInheritsJavaInterface.kt"); - } - } -}