diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/library/A.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/library/A.kt new file mode 100644 index 00000000000..b350cf24c72 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/library/A.kt @@ -0,0 +1,3 @@ +package test + +interface IA : IBase diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/library/B.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/library/B.kt new file mode 100644 index 00000000000..06fbd0abafb --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/library/B.kt @@ -0,0 +1,6 @@ +package test + +sealed class B : Base(), IBase { + class First : B() + class Second : B() +} diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/library/Base.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/library/Base.kt new file mode 100644 index 00000000000..7e707c9b6a2 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/library/Base.kt @@ -0,0 +1,5 @@ +package test + +sealed interface IBase + +sealed class Base diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/library/C.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/library/C.kt new file mode 100644 index 00000000000..30034bc8027 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/library/C.kt @@ -0,0 +1,5 @@ +package test + +enum class C : IBase { + SomeValue, AnotherValue +} diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/library/D.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/library/D.kt new file mode 100644 index 00000000000..5cdbef39915 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/library/D.kt @@ -0,0 +1,3 @@ +package test + +object D : Base(), IBase diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/main.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/main.kt new file mode 100644 index 00000000000..1dd93074578 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/main.kt @@ -0,0 +1,36 @@ +import test.* + +fun test_1(base: IBase) { + val x = when (base) { + is IA -> 1 + is B -> 2 + is C -> 3 + is D -> 4 + } +} + +fun test_2(base: IBase) { + val x = when (base) { + is IA -> 1 + is B.First -> 2 + is B.Second -> 3 + C.SomeValue -> 4 + C.AnotherValue -> 5 + D -> 6 + } +} + +fun test_3(base: Base) { + val x = when (base) { + is B -> 2 + is D -> 4 + } +} + +fun test_4(base: Base) { + val x = when (base) { + is B.First -> 2 + is B.Second -> 3 + D -> 6 + } +} diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/output.txt b/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/output.txt new file mode 100644 index 00000000000..e4d9b26ce29 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/output.txt @@ -0,0 +1,23 @@ +warning: ATTENTION! +This build uses unsafe internal compiler arguments: + +-XXLanguage:+FreedomForSealedClasses +-XXLanguage:+SealedInterfaces + +This mode is not recommended for production use, +as no stability/compatibility guarantees are given on +compiler or generated code. Use it at your own risk! + +compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/main.kt:4:9: warning: variable 'x' is never used + val x = when (base) { + ^ +compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/main.kt:13:9: warning: variable 'x' is never used + val x = when (base) { + ^ +compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/main.kt:24:9: warning: variable 'x' is never used + val x = when (base) { + ^ +compiler/testData/compileKotlinAgainstCustomBinaries/sealedClassesAndInterfaces/main.kt:31:9: warning: variable 'x' is never used + val x = when (base) { + ^ +OK diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt index cfe3369ee02..64626e8ce3c 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt @@ -694,6 +694,12 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-Xallow-jvm-ir-dependencies")) } + fun testSealedClassesAndInterfaces() { + val features = listOf("-XXLanguage:+FreedomForSealedClasses", "-XXLanguage:+SealedInterfaces") + val library = compileLibrary("library", additionalOptions = features, checkKotlinOutput = {}) + compileKotlin("main.kt", tmpdir, listOf(library), additionalOptions = features) + } + // If this test fails, then bootstrap compiler most likely should be advanced fun testPreReleaseFlagIsConsistentBetweenBootstrapAndCurrentCompiler() { val bootstrapCompiler = JarFile(PathUtil.kotlinPathsForCompiler.compilerPath)