Reflection: deprecate KClass.defaultType

Its semantics were unclear and its javaType was implemented incorrectly (it
should have returned ParameterizedType with star projections for generic type)
This commit is contained in:
Alexander Udalov
2016-07-26 18:41:41 +03:00
parent 6b79782951
commit f958483e56
3 changed files with 3 additions and 33 deletions
@@ -1,27 +0,0 @@
// WITH_REFLECT
import kotlin.reflect.defaultType
import kotlin.reflect.jvm.javaType
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
class Simple
class Generic<K, V> {
fun thiz() = this
}
fun simple() = Simple()
fun genericIntString() = Generic<Int, String>()
fun box(): String {
assertEquals(Simple::class.java, Simple::class.defaultType.javaType)
assertEquals(::simple.returnType, Simple::class.defaultType)
assertEquals(Generic::class.java, Generic::class.defaultType.javaType)
assertEquals(Generic<*, *>::thiz.returnType, Generic::class.defaultType)
// Generic<Int, String> != Generic<K, V>
assertNotEquals(::genericIntString.returnType, Generic::class.defaultType)
return "OK"
}
@@ -11892,12 +11892,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("defaultType.kt")
public void testDefaultType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/classes/defaultType.kt");
doTest(fileName);
}
@TestMetadata("jvmName.kt")
public void testJvmName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/classes/jvmName.kt");
@@ -54,6 +54,9 @@ val KClass<*>.companionObjectInstance: Any?
* Returns a type corresponding to the given class with type parameters of that class substituted as the corresponding arguments.
* For example, for class `MyMap<K, V>` [defaultType] would return the type `MyMap<K, V>`.
*/
@Deprecated("This function creates a type which rarely makes sense for generic classes. " +
"For example, such type can only be used in signatures of members of that class. " +
"Use starProjectedType or createType() for clearer semantics.")
val KClass<*>.defaultType: KType
get() = KTypeImpl((this as KClassImpl<*>).descriptor.defaultType) { jClass }