Write/load subclasses of sealed classes in metadata

Note that now DeserializedClassDescriptor.getSealedSubclasses works a lot
faster than before, for all newly compiled sealed classes except empty ones. It
may be optimized further if we look at the metadata version of the file the
class was loaded from, however it's not easy currently because
DeserializedClassDescriptor is declared in common (non-JVM) code and has no
direct access to the binary version information.

This will also allow to add a reflection API to get subclasses of a sealed
class

 #KT-12795 Fixed
This commit is contained in:
Alexander Udalov
2016-12-30 18:33:36 +03:00
parent 75a4958144
commit 7107ee2eeb
9 changed files with 540 additions and 126 deletions
@@ -0,0 +1,38 @@
// FILE: A.kt
package a
sealed class Empty
sealed class OnlyNested {
class Nested : OnlyNested()
}
sealed class NestedAndTopLevel {
class Nested : NestedAndTopLevel()
}
class TopLevel : NestedAndTopLevel()
// FILE: B.kt
import a.*
// This test checks that we correctly load subclasses of a compiled sealed class from binaries.
// It's not a diagnostic test because there are no diagnostic tests where resolution is performed against compiled Kotlin binaries
fun empty(e: Empty): String = when (e) {
else -> "1"
}
fun onlyNested(on: OnlyNested): String = when (on) {
is OnlyNested.Nested -> "2"
}
fun nestedAndTopLevel(natl: NestedAndTopLevel): String = when (natl) {
is NestedAndTopLevel.Nested -> "3"
is TopLevel -> "4"
}
fun box(): String {
return "OK"
}