Files
kotlin-fork/compiler/testData/codegen/box/reflection/classes/nestedClasses.kt
T
Alexander Udalov d4b5599373 Add JVM target bytecode version 21
Unfortunately, there are still problems with running JVM backend tests
with JVM target 21 because:

1) The D8 version that we use does not support bytecode version 21, and
   updating to a newer version requires to change JVM target of compiler
   tests to 11. This will be addressed separately when we enable JVM 21
   in tests-different-jdk.
2) Some tests are failing because of KT-60659 and KT-60770:
   - builtinStubMethods/bridgesForStubs/emptyStringListAdd.kt
   - jdk/stream.kt
   - regressions/kt528.kt

 #KT-60662 Fixed
2023-08-03 08:43:22 +00:00

62 lines
2.4 KiB
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_REFLECT
// FULL_JDK
import kotlin.reflect.KClass
import kotlin.test.assertEquals
class A {
companion object {}
inner class Inner
class Nested
private class PrivateNested
}
fun nestedNames(c: KClass<*>) = c.nestedClasses.map { it.simpleName ?: throw AssertionError("Unnamed class: ${it.java}") }.sorted()
fun box(): String {
// Kotlin class without nested classes
assertEquals(emptyList<String>(), nestedNames(A.Inner::class))
// Kotlin class with nested classes
assertEquals(listOf("Companion", "Inner", "Nested", "PrivateNested"), nestedNames(A::class))
// Java class without nested classes
assertEquals(emptyList<String>(), nestedNames(Error::class))
// Java interface with nested classes
assertEquals(listOf("Entry"), nestedNames(java.util.Map::class))
// Java class with nested classes
assertEquals(listOf("SimpleEntry", "SimpleImmutableEntry"), nestedNames(java.util.AbstractMap::class) - "ViewCollection")
// Built-ins
assertEquals(emptyList<String>(), nestedNames(Array<Any>::class))
assertEquals(emptyList<String>(), nestedNames(CharSequence::class))
assertEquals(listOf("Companion"), nestedNames(String::class))
assertEquals(emptyList<String>(), nestedNames(Collection::class))
assertEquals(emptyList<String>(), nestedNames(MutableCollection::class))
assertEquals(emptyList<String>(), nestedNames(List::class))
assertEquals(emptyList<String>(), nestedNames(MutableList::class))
assertEquals(listOf("Entry"), nestedNames(Map::class))
assertEquals(emptyList<String>(), nestedNames(Map.Entry::class))
assertEquals(emptyList<String>(), nestedNames(MutableMap.MutableEntry::class))
// TODO: should be MutableEntry. Currently we do not distinguish between Map and MutableMap.
assertEquals(listOf("Entry"), nestedNames(MutableMap::class))
// Primitives
for (primitive in listOf(Byte::class, Double::class, Float::class, Int::class, Long::class, Short::class, Char::class, Boolean::class)) {
assertEquals(listOf("Companion"), nestedNames(primitive))
}
// Primitive arrays
for (primitiveArray in listOf(
ByteArray::class, DoubleArray::class, FloatArray::class, IntArray::class,
LongArray::class, ShortArray::class, CharArray::class, BooleanArray::class
)) {
assertEquals(emptyList<String>(), nestedNames(primitiveArray))
}
return "OK"
}