Support reflection tests on Android
This commit is contained in:
+61
-17
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.codegen.CodegenTestCase
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import java.io.File
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@@ -31,8 +30,10 @@ private val packagePattern = Pattern.compile("(?m)^\\s*package[ |\t]+([\\w|\\.]*
|
||||
|
||||
private val importPattern = Pattern.compile("import[ |\t]([\\w|]*\\.)")
|
||||
|
||||
private data class OldPackageAndNew(val oldFqName: FqName, val newFqName: FqName)
|
||||
|
||||
internal fun patchFiles(
|
||||
file: File,
|
||||
testFile: File,
|
||||
testFiles: List<CodegenTestCase.TestFile>,
|
||||
filesHolder: CodegenTestsOnAndroidGenerator.FilesWriter
|
||||
): FqName? {
|
||||
@@ -43,11 +44,11 @@ internal fun patchFiles(
|
||||
val ktFiles = testFiles.filter { it.name.endsWith(".kt") }
|
||||
if (ktFiles.isEmpty()) return null
|
||||
|
||||
val newPackagePrefix = file.path.replace("\\\\|-|\\.|/".toRegex(), "_")
|
||||
val newPackagePrefix = testFile.path.replace("\\\\|-|\\.|/".toRegex(), "_")
|
||||
val oldPackage = Ref<FqName>()
|
||||
val isSingle = testFiles.size == 1
|
||||
val resultFiles = testFiles.map {
|
||||
val fileName = if (isSingle) it.name else file.name.substringBeforeLast(".kt") + "/" + it.name
|
||||
val fileName = if (isSingle) it.name else testFile.name.substringBeforeLast(".kt") + "/" + it.name
|
||||
TestClassInfo(
|
||||
fileName,
|
||||
changePackage(newPackagePrefix, it.content, oldPackage),
|
||||
@@ -55,21 +56,51 @@ internal fun patchFiles(
|
||||
getGeneratedClassName(File(fileName), it.content, newPackagePrefix, oldPackage.get())
|
||||
)
|
||||
}
|
||||
val packages =
|
||||
resultFiles.map { OldPackageAndNew(it.oldPackage, it.newClassId.parent()) }.sortedByDescending { it.oldFqName.asString().length }
|
||||
|
||||
/*replace all Class.forName*/
|
||||
resultFiles.forEach {
|
||||
file ->
|
||||
file.content = resultFiles.fold(file.content) { r, param ->
|
||||
patchClassForName(param.newClassId, param.oldPackage, r)
|
||||
//If files contain any val or var declaration with same name as any package name
|
||||
// then use old conservative renaming scheme, otherwise use aggressive one
|
||||
// with old package renaming to new one (except some cases for default package)
|
||||
// Example for conservative switch:
|
||||
// package foo
|
||||
// ...
|
||||
// val foo = ....
|
||||
// class A(val foo ...)
|
||||
// fun foo()= { var foo ...}
|
||||
val conservativeRenameScheme = resultFiles.any { file ->
|
||||
packages.any {
|
||||
if (it.oldFqName.isRoot || !it.oldFqName.parent().isRoot) false
|
||||
else file.content.contains("(val|var)\\s+${it.oldFqName.asString()}[^A-Za-z0-9_.]".toRegex())
|
||||
}
|
||||
}
|
||||
|
||||
/*patch imports and self imports*/
|
||||
resultFiles.forEach {
|
||||
file ->
|
||||
if (!conservativeRenameScheme) {
|
||||
/*replace all packages*/
|
||||
resultFiles.forEach { file ->
|
||||
file.content = packages.fold(file.content) { r, param ->
|
||||
patchPackages(param.newFqName, param.oldFqName, r)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//patch imports
|
||||
resultFiles.forEach { file ->
|
||||
file.content = packages.fold(file.content) { r, param ->
|
||||
r.patchImports(param.oldFqName, param.newFqName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*replace all Class.forName*/
|
||||
resultFiles.forEach { file ->
|
||||
file.content = resultFiles.fold(file.content) { r, param ->
|
||||
r.patchImports(param.oldPackage, param.newPackage)
|
||||
}.patchSelfImports(file.newPackage)
|
||||
patchClassForName(param.newClassId, param.oldPackage, r, conservativeRenameScheme)
|
||||
}
|
||||
}
|
||||
|
||||
//patch self imports
|
||||
resultFiles.forEach { file ->
|
||||
file.content = file.content.patchSelfImports(file.newPackage)
|
||||
}
|
||||
|
||||
resultFiles.forEach { resultFile ->
|
||||
@@ -80,7 +111,7 @@ internal fun patchFiles(
|
||||
|
||||
val boxFiles = resultFiles.filter { hasBoxMethod(it.content) }
|
||||
if (boxFiles.size != 1) {
|
||||
println("Several box methods in $file")
|
||||
println("Several box methods in $testFile")
|
||||
}
|
||||
return boxFiles.last().newClassId
|
||||
}
|
||||
@@ -132,8 +163,21 @@ private fun getGeneratedClassName(file: File, text: String, newPackagePrefix: St
|
||||
return PackagePartClassUtils.getPackagePartFqName(packageFqName, file.name)
|
||||
}
|
||||
|
||||
private fun patchClassForName(className: FqName, oldPackage: FqName, text: String): String {
|
||||
return text.replace(("Class\\.forName\\(\"" + oldPackage.child(className.shortName()).asString() + "\"\\)").toRegex(), "Class.forName(\"" + className.asString() + "\")")
|
||||
private fun patchClassForName(className: FqName, oldPackage: FqName, text: String, conservativeRenameSchemeheme: Boolean): String {
|
||||
if (!conservativeRenameSchemeheme && !oldPackage.isRoot) return text
|
||||
return text.replace(
|
||||
("Class\\.forName\\(\"" + oldPackage.child(className.shortName()).asString()).toRegex(),
|
||||
"Class.forName(\"" + className.asString()
|
||||
)
|
||||
}
|
||||
|
||||
private fun patchPackages(newPackage: FqName, oldPackage: FqName, text: String): String {
|
||||
if (oldPackage.isRoot) return text
|
||||
|
||||
val regexp = "([^A-Za-z0-9.])" + (oldPackage.asString() + ".").replace(".", "\\.")
|
||||
return text.replace(
|
||||
regexp.toRegex(), "$1" + newPackage.asString() + "."
|
||||
)
|
||||
}
|
||||
|
||||
private fun String.patchImports(oldPackage: FqName, newPackage: FqName): String {
|
||||
|
||||
@@ -33,62 +33,25 @@ public class SpecialFiles {
|
||||
private static void fillExcludedFiles() {
|
||||
// Reflection
|
||||
excludedFiles.add("enclosing");
|
||||
excludedFiles.add("noReflectAtRuntime");
|
||||
excludedFiles.add("methodsFromAny");
|
||||
excludedFiles.add("genericProperty.kt");
|
||||
excludedFiles.add("kt3238.kt");
|
||||
excludedFiles.add("kt1482_2279.kt");
|
||||
excludedFiles.add("extensionMethod.kt");
|
||||
excludedFiles.add("functionNtoStringNoReflect.kt");
|
||||
excludedFiles.add("innerGeneric.kt");
|
||||
excludedFiles.add("simpleCreateType.kt");
|
||||
excludedFiles.add("equalsHashCodeToString.kt");
|
||||
excludedFiles.add("arrayOfKClasses.kt");
|
||||
excludedFiles.add("enumKClassAnnotation.kt");
|
||||
excludedFiles.add("primitivesAndArrays.kt");
|
||||
excludedFiles.add("getDelegateWithoutReflection.kt");
|
||||
excludedFiles.add("parameterAnnotationInDefaultImpls.kt");
|
||||
excludedFiles.add("kt17091.kt");
|
||||
excludedFiles.add("kt17091_2.kt");
|
||||
excludedFiles.add("kt17091_3.kt");
|
||||
excludedFiles.add("kt22906.kt");
|
||||
excludedFiles.add("kt10259.kt");
|
||||
excludedFiles.add("simpleClassLiteral.kt");
|
||||
|
||||
// Reflection is used to check full class name
|
||||
excludedFiles.add("native");
|
||||
//UnsatisfiedLinkError
|
||||
excludedFiles.add("nativePropertyAccessors.kt");
|
||||
excludedFiles.add("topLevel.kt");
|
||||
|
||||
//Test with no reflection at runtime
|
||||
excludedFiles.add("noReflectAtRuntime");
|
||||
excludedFiles.add("functionNtoStringNoReflect.kt");
|
||||
excludedFiles.add("getDelegateWithoutReflection.kt");
|
||||
|
||||
// "IOOBE: Invalid index 4, size is 4" for java.lang.reflect.ParameterizedType on Android
|
||||
excludedFiles.add("innerGenericTypeArgument.kt");
|
||||
|
||||
// Cannot change package name
|
||||
excludedFiles.add("nestedInPackage.kt");
|
||||
excludedFiles.add("packageQualifiedMethod.kt");
|
||||
excludedFiles.add("classObjectToString.kt");
|
||||
excludedFiles.add("assertionStackTrace.kt");
|
||||
excludedFiles.add("anonymousObjectReifiedSupertype.kt");
|
||||
excludedFiles.add("innerAnonymousObject.kt");
|
||||
excludedFiles.add("nestedReifiedSignature.kt");
|
||||
excludedFiles.add("recursiveInnerAnonymousObject.kt");
|
||||
excludedFiles.add("approximateCapturedTypes.kt");
|
||||
excludedFiles.add("classForEnumEntry.kt");
|
||||
excludedFiles.add("kt10143.kt");
|
||||
excludedFiles.add("internalTopLevelOtherPackage.kt");
|
||||
excludedFiles.add("noPrivateDelegation.kt");
|
||||
excludedFiles.add("platformTypeAssertionStackTrace.kt");
|
||||
excludedFiles.add("packages.kt");
|
||||
excludedFiles.add("kt10259.kt");
|
||||
excludedFiles.add("kt11081.kt");
|
||||
excludedFiles.add("kt6990.kt");
|
||||
excludedFiles.add("mainInFiles.kt");
|
||||
excludedFiles.add("noClassForSimpleEnum.kt");
|
||||
excludedFiles.add("simpleClassLiteral.kt");
|
||||
excludedFiles.add("jvmName.kt");
|
||||
excludedFiles.add("qualifiedName.kt");
|
||||
excludedFiles.add("topLevelProperty.kt");
|
||||
excludedFiles.add("typeParameters.kt");
|
||||
excludedFiles.add("kt13133.kt");
|
||||
excludedFiles.add("genericOverriddenFunction.kt");
|
||||
excludedFiles.add("genericOverriddenProperty.kt");
|
||||
excludedFiles.add("genericProperty.kt");
|
||||
|
||||
// StackOverflow with StringBuilder (escape())
|
||||
excludedFiles.add("kt684.kt");
|
||||
@@ -96,18 +59,6 @@ public class SpecialFiles {
|
||||
// Wrong enclosing info or signature after package renaming
|
||||
excludedFiles.add("enclosingInfo");
|
||||
excludedFiles.add("signature");
|
||||
excludedFiles.add("genericBackingFieldSignature.kt");
|
||||
excludedFiles.add("genericMethodSignature.kt");
|
||||
excludedFiles.add("kt11121.kt");
|
||||
excludedFiles.add("kt5112.kt");
|
||||
|
||||
// Different format of inner signature on Android and JVM
|
||||
excludedFiles.add("signatureOfDeepGenericInner.kt");
|
||||
excludedFiles.add("signatureOfDeepInner.kt");
|
||||
excludedFiles.add("signatureOfDeepInnerLastGeneric.kt");
|
||||
excludedFiles.add("signatureOfGenericInnerGenericOuter.kt");
|
||||
excludedFiles.add("signatureOfGenericInnerSimpleOuter.kt");
|
||||
excludedFiles.add("signatureOfSimpleInnerSimpleOuter.kt");
|
||||
|
||||
// Some classes are not visible on android
|
||||
excludedFiles.add("classpath.kt");
|
||||
@@ -120,8 +71,6 @@ public class SpecialFiles {
|
||||
|
||||
// Additional nested class in 'Thread' class on Android
|
||||
excludedFiles.add("nestedClasses.kt");
|
||||
// No 'modifiers' field in 'java.lang.reflect.Field' class
|
||||
excludedFiles.add("kt12200Const.kt");
|
||||
|
||||
// KT-8120
|
||||
excludedFiles.add("closureOfInnerLocalClass.kt");
|
||||
|
||||
+3
-1
@@ -3,6 +3,8 @@
|
||||
// FULL_JDK
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
annotation class Anno(val value: String)
|
||||
|
||||
interface Test {
|
||||
@@ -10,7 +12,7 @@ interface Test {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val testMethod = Class.forName("Test\$DefaultImpls").declaredMethods.single()
|
||||
val testMethod = Class.forName("test.Test\$DefaultImpls").declaredMethods.single()
|
||||
//return (::test.parameters.single().annotations.single() as Simple).value
|
||||
val receiverAnnotations = (testMethod.parameters[0]).annotations
|
||||
if (receiverAnnotations.isNotEmpty()) return "fail: receiver parameter should not have any annotations, but: ${receiverAnnotations.joinToString()}"
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
|
||||
package test
|
||||
|
||||
interface Test<T> {
|
||||
fun test(p: T): T {
|
||||
return null!!
|
||||
@@ -34,7 +36,7 @@ fun box(): String {
|
||||
checkMethodExists(TestClass::class.java, "foo", String::class.java)
|
||||
|
||||
|
||||
val test2DefaultImpls = java.lang.Class.forName("Test2\$DefaultImpls")
|
||||
val test2DefaultImpls = java.lang.Class.forName("test.Test2\$DefaultImpls")
|
||||
checkMethodExists(test2DefaultImpls, "test", Test2::class.java, String::class.java)
|
||||
checkMethodExists(test2DefaultImpls, "foo", Test2::class.java, String::class.java)
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
|
||||
package test
|
||||
|
||||
interface Test<T> {
|
||||
var T.foo: T
|
||||
get() = null!!
|
||||
@@ -27,7 +29,7 @@ fun box(): String {
|
||||
checkMethodExists(TestClass::class.java, "setFoo", Any::class.java, Any::class.java)
|
||||
checkMethodExists(TestClass::class.java, "setFoo", String::class.java, String::class.java)
|
||||
|
||||
val test2DefaultImpls = java.lang.Class.forName("Test2\$DefaultImpls")
|
||||
val test2DefaultImpls = java.lang.Class.forName("test.Test2\$DefaultImpls")
|
||||
checkMethodExists(test2DefaultImpls, "getFoo", Test2::class.java, String::class.java)
|
||||
checkMethodExists(test2DefaultImpls, "setFoo", Test2::class.java, String::class.java, String::class.java)
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
// TODO: Enable for JS when it supports Java class library.
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
package test
|
||||
|
||||
class SomeClass { companion object }
|
||||
|
||||
fun box() =
|
||||
if ((SomeClass.toString() as java.lang.String).matches("SomeClass\\\$Companion@[0-9a-fA-F]+"))
|
||||
fun box() =
|
||||
if ((SomeClass.toString() as java.lang.String).matches("test.SomeClass\\\$Companion@[0-9a-fA-F]+"))
|
||||
"OK"
|
||||
else
|
||||
"Fail: $SomeClass"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
// WITH_COROUTINES
|
||||
|
||||
package test
|
||||
import helpers.*
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
@@ -31,5 +31,5 @@ fun box(): String {
|
||||
result = A<String>().bar()
|
||||
}
|
||||
|
||||
return if (result == "Continuation at A.bar(coroutineToString.kt:16)") "OK" else "Fail: $result"
|
||||
return if (result == "Continuation at test.A.bar(coroutineToString.kt:16)") "OK" else "Fail: $result"
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
// WITH_COROUTINES
|
||||
|
||||
package test
|
||||
import helpers.*
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// WITH_COROUTINES
|
||||
|
||||
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "CANNOT_OVERRIDE_INVISIBLE_MEMBER")
|
||||
|
||||
package test
|
||||
import helpers.*
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
+6
-4
@@ -2,6 +2,8 @@
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
package test
|
||||
|
||||
enum class IssueState {
|
||||
DEFAULT,
|
||||
FIXED {
|
||||
@@ -15,15 +17,15 @@ fun box(): String {
|
||||
val field = IssueState::class.java.getField("FIXED")
|
||||
|
||||
val typeName = field.type.name
|
||||
if (typeName != "IssueState") return "Fail type name: $typeName"
|
||||
if (typeName != "test.IssueState") return "Fail type name: $typeName"
|
||||
|
||||
val className = field.get(null).javaClass.name
|
||||
if (className != "IssueState\$FIXED") return "Fail class name: $className"
|
||||
if (className != "test.IssueState\$FIXED") return "Fail class name: $className"
|
||||
|
||||
val classLoader = IssueState::class.java.classLoader
|
||||
classLoader.loadClass("IssueState\$FIXED")
|
||||
classLoader.loadClass("test.IssueState\$FIXED")
|
||||
try {
|
||||
classLoader.loadClass("IssueState\$DEFAULT")
|
||||
classLoader.loadClass("test.IssueState\$DEFAULT")
|
||||
return "Fail: no class should have been generated for DEFAULT"
|
||||
}
|
||||
catch (e: Exception) {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
package test
|
||||
|
||||
enum class State {
|
||||
O,
|
||||
K
|
||||
@@ -10,7 +12,7 @@ enum class State {
|
||||
fun box(): String {
|
||||
val field = State::class.java.getField("O")
|
||||
val className = field.get(null).javaClass.name
|
||||
if (className != "State") return "Fail: $className"
|
||||
if (className != "test.State") return "Fail: $className"
|
||||
|
||||
return "${State.O.name}${State.K.name}"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
// FULL_JDK
|
||||
|
||||
package test
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun box(): String {
|
||||
@@ -17,7 +19,7 @@ fun box(): String {
|
||||
return "Fail: very small stack trace, should at least have current function and JUnit reflective calls: ${Arrays.toString(st)}"
|
||||
}
|
||||
val top = st[0]
|
||||
if (!(top.getClassName() == "PlatformTypeAssertionStackTraceKt" && top.getMethodName() == "box")) {
|
||||
if (!(top.getClassName() == "test.PlatformTypeAssertionStackTraceKt" && top.getMethodName() == "box")) {
|
||||
return "Fail: top stack trace element should be PlatformTypeAssertionStackTraceKt.box() from default package, but was $top"
|
||||
}
|
||||
return "OK"
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ fun box(): String {
|
||||
var s = ""
|
||||
val name = "equals-impl0"
|
||||
val specializedEquals =
|
||||
Class.forName("Simple").getDeclaredMethod(name, String::class.java, String::class.java)
|
||||
Simple::class.java.getDeclaredMethod(name, String::class.java, String::class.java)
|
||||
?: return "$name not found"
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
@@ -15,14 +16,13 @@ annotation class Meta(val anno: Anno)
|
||||
@Meta(Anno(value = "OK"))
|
||||
fun bar() {}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val f = Foo::class.annotations.single()
|
||||
assertTrue("@Anno\\(uglyJvmName=\"?OK\"?\\)".toRegex().matches(f.toString()))
|
||||
assertTrue("@test.Anno\\(uglyJvmName=\"?OK\"?\\)".toRegex().matches(f.toString()))
|
||||
assertEquals("OK", (f as Anno).value)
|
||||
|
||||
val b = ::bar.annotations.single()
|
||||
assertEquals("@Meta(anno=$f)", b.toString())
|
||||
assertEquals("@test.Meta(anno=$f)", b.toString())
|
||||
assertEquals("OK", (b as Meta).anno.value)
|
||||
|
||||
return "OK"
|
||||
|
||||
@@ -10,6 +10,6 @@ class C {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val m = C::class.java.getClassLoader().loadClass("ExtensionMethodKt").getMethod("foo", C::class.java, String::class.java)
|
||||
val m = Class.forName("ExtensionMethodKt").getMethod("foo", C::class.java, String::class.java)
|
||||
return m.invoke(null, C(), "O") as String
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
// WITH_RUNTIME
|
||||
|
||||
object Obj {
|
||||
class Inner() {
|
||||
@@ -9,7 +10,7 @@ object Obj {
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val klass = Class.forName("Obj\$Inner")!!
|
||||
val klass = Obj.Inner::class.java
|
||||
val cons = klass.getConstructors()!![0]
|
||||
val inner = cons.newInstance(*(arrayOfNulls<String>(0) as Array<String>))
|
||||
return "OK"
|
||||
|
||||
+3
-1
@@ -1,10 +1,12 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
package test
|
||||
|
||||
abstract class ClassValAbstract {
|
||||
abstract var a: Int
|
||||
|
||||
companion object {
|
||||
val methods = (this as java.lang.Object).getClass()?.getClassLoader()?.loadClass("ClassValAbstract")?.getMethods()!!
|
||||
val methods = ClassValAbstract::class.java.getMethods()!!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// WITH_REFLECT
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR, JS, NATIVE
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
annotation class Ann1
|
||||
@@ -16,6 +18,6 @@ fun box(): String {
|
||||
val setterParameters = Foo::delegate.setter.parameters
|
||||
assertEquals(2, setterParameters.size)
|
||||
assertEquals("[]", setterParameters.first().annotations.toString())
|
||||
assertEquals("[@Ann2(), @Ann1()]", setterParameters.last().annotations.toString())
|
||||
assertEquals("[@test.Ann2(), @test.Ann1()]", setterParameters.last().annotations.toString())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
class A
|
||||
|
||||
data class D(val s: String)
|
||||
@@ -14,7 +16,7 @@ fun box(): String {
|
||||
assert(A::equals.call(a, a))
|
||||
assert(!A::equals.call(a, 0))
|
||||
assert(A::hashCode.call(a) == A::hashCode.call(a))
|
||||
assert(A::toString.call(a).startsWith("A@"))
|
||||
assert(A::toString.call(a).startsWith("test.A@"))
|
||||
|
||||
assert(D::equals.call(D("foo"), D("foo")))
|
||||
assert(!D::equals.call(D("foo"), D("bar")))
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.reflect.jvm.jvmName
|
||||
@@ -12,17 +14,17 @@ class Klass {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Klass", Klass::class.jvmName)
|
||||
assertEquals("Klass\$Nested", Klass.Nested::class.jvmName)
|
||||
assertEquals("Klass\$Companion", Klass.Companion::class.jvmName)
|
||||
assertEquals("test.Klass", Klass::class.jvmName)
|
||||
assertEquals("test.Klass\$Nested", Klass.Nested::class.jvmName)
|
||||
assertEquals("test.Klass\$Companion", Klass.Companion::class.jvmName)
|
||||
|
||||
class Local
|
||||
val l = Local::class.jvmName
|
||||
assertTrue(l != null && l.startsWith("JvmNameKt\$") && "\$box\$" in l && l.endsWith("\$Local"))
|
||||
assertTrue(l != null && l.startsWith("test.JvmNameKt\$") && "\$box\$" in l && l.endsWith("\$Local"))
|
||||
|
||||
val obj = object {}
|
||||
val o = obj.javaClass.kotlin.jvmName
|
||||
assertTrue(o != null && o.startsWith("JvmNameKt\$") && "\$box\$" in o && o.endsWith("\$1"))
|
||||
assertTrue(o != null && o.startsWith("test.JvmNameKt\$") && "\$box\$" in o && o.endsWith("\$1"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class Klass {
|
||||
@@ -11,9 +13,9 @@ class Klass {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Klass", Klass::class.qualifiedName)
|
||||
assertEquals("Klass.Nested", Klass.Nested::class.qualifiedName)
|
||||
assertEquals("Klass.Companion", Klass.Companion::class.qualifiedName)
|
||||
assertEquals("test.Klass", Klass::class.qualifiedName)
|
||||
assertEquals("test.Klass.Nested", Klass.Nested::class.qualifiedName)
|
||||
assertEquals("test.Klass.Companion", Klass.Companion::class.qualifiedName)
|
||||
|
||||
class Local
|
||||
assertEquals(null, Local::class.qualifiedName)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: JS_IR, JS, NATIVE
|
||||
// WITH_REFLECT
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -18,7 +19,7 @@ enum class TestEnum(val id: String? = null) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(listOf("fun <init>(kotlin.String?): TestEnum"), TestEnum.ENUM1::class.constructors.map { it.toString() })
|
||||
assertEquals(listOf("fun <init>(kotlin.String?): test.TestEnum"), TestEnum.ENUM1::class.constructors.map { it.toString() })
|
||||
assertEquals(listOf(), TestEnum.ENUM2::class.constructors.map { it.toString() })
|
||||
|
||||
return "OK"
|
||||
|
||||
+2
-1
@@ -4,6 +4,7 @@
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
package test
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.test.assertEquals
|
||||
@@ -13,6 +14,6 @@ annotation class Anno(val klasses: Array<KClass<*>> = arrayOf(String::class, Int
|
||||
fun box(): String {
|
||||
val anno = Anno::class.constructors.single().callBy(emptyMap())
|
||||
assertEquals(listOf(String::class, Int::class), anno.klasses.toList())
|
||||
assertEquals("@Anno(klasses=[class java.lang.String, int])", anno.toString())
|
||||
assertEquals("@test.Anno(klasses=[class java.lang.String, int])", anno.toString())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+3
-2
@@ -4,6 +4,7 @@
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
package test
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.test.assertEquals
|
||||
@@ -45,8 +46,8 @@ fun box(): String {
|
||||
assertEquals(a2, a1)
|
||||
assertEquals(a1.hashCode(), a2.hashCode())
|
||||
|
||||
assertEquals("@Anno(level=WARNING, klass=class java.lang.Number, foo=@Foo(value=OK), " +
|
||||
"levels=[WARNING], klasses=[class java.lang.Number], foos=[@Foo(value=OK)])", a1.toString())
|
||||
assertEquals("@test.Anno(level=WARNING, klass=class java.lang.Number, foo=@test.Foo(value=OK), " +
|
||||
"levels=[WARNING], klasses=[class java.lang.Number], foos=[@test.Foo(value=OK)])", a1.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+3
-1
@@ -5,6 +5,8 @@
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
annotation class Anno(
|
||||
@@ -79,7 +81,7 @@ fun box(): String {
|
||||
assertEquals(a2, a1)
|
||||
assertEquals(a1.hashCode(), a2.hashCode())
|
||||
|
||||
assertEquals("@Anno(b=1, c=x, d=3.14, f=-2.72, i=42424242, j=239239239239239, s=42, z=true, " +
|
||||
assertEquals("@test.Anno(b=1, c=x, d=3.14, f=-2.72, i=42424242, j=239239239239239, s=42, z=true, " +
|
||||
"ba=[-1], ca=[y], da=[-3.14159], fa=[2.7218], ia=[424242], ja=[239239239239], sa=[-43], za=[false, true], " +
|
||||
"str=lol, stra=[rofl])", a1.toString())
|
||||
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
// IGNORE_BACKEND: JS_IR, JS, NATIVE
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
enum class E { X, Y, Z }
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("fun values(): kotlin.Array<E>", E::values.toString())
|
||||
assertEquals("fun values(): kotlin.Array<test.E>", E::values.toString())
|
||||
assertEquals(listOf(E.X, E.Y, E.Z), E::values.call().toList())
|
||||
assertEquals("fun valueOf(kotlin.String): E", E::valueOf.toString())
|
||||
assertEquals("fun valueOf(kotlin.String): test.E", E::valueOf.toString())
|
||||
assertEquals(E.Y, E::valueOf.call("Y"))
|
||||
|
||||
return "OK"
|
||||
|
||||
+3
-1
@@ -5,6 +5,8 @@
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
interface H<T> {
|
||||
@@ -14,7 +16,7 @@ interface H<T> {
|
||||
interface A : H<A>
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("A?", A::foo.returnType.toString())
|
||||
assertEquals("test.A?", A::foo.returnType.toString())
|
||||
assertEquals("T?", H<A>::foo.returnType.toString())
|
||||
|
||||
return "OK"
|
||||
|
||||
+6
-4
@@ -3,6 +3,8 @@
|
||||
|
||||
// WITH_REFLECT
|
||||
//test for KT-3722 Write correct generic type information for generated fields
|
||||
package test
|
||||
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class Z<T> {
|
||||
@@ -50,25 +52,25 @@ fun box(): String {
|
||||
|
||||
val classField = clz.getDeclaredField("classField1");
|
||||
|
||||
if (classField.getGenericType().toString() != "Z<T>")
|
||||
if (classField.getGenericType().toString() != "test.Z<T>")
|
||||
return "fail1: " + classField.getGenericType();
|
||||
|
||||
|
||||
val classField2 = clz.getDeclaredField("classField2");
|
||||
|
||||
if (classField2.getGenericType().toString() != "Z<java.lang.String>")
|
||||
if (classField2.getGenericType().toString() != "test.Z<java.lang.String>")
|
||||
return "fail2: " + classField2.getGenericType();
|
||||
|
||||
|
||||
val classField3 = clz.getDeclaredField("classField3");
|
||||
|
||||
if (classField3.getGenericType().toString() != "Zout<java.lang.String>")
|
||||
if (classField3.getGenericType().toString() != "test.Zout<java.lang.String>")
|
||||
return "fail3: " + classField3.getGenericType();
|
||||
|
||||
|
||||
val classField4 = clz.getDeclaredField("classField4");
|
||||
|
||||
if (classField4.getGenericType().toString() != "Zin<TParam>")
|
||||
if (classField4.getGenericType().toString() != "test.Zin<test.TParam>")
|
||||
return "fail4: " + classField4.getGenericType();
|
||||
|
||||
val classField5 = clz.getDeclaredField("delegateLazy\$delegate");
|
||||
|
||||
+6
-4
@@ -2,6 +2,8 @@
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
class Z<T> {}
|
||||
|
||||
class TParam {}
|
||||
@@ -30,10 +32,10 @@ fun box(): String {
|
||||
|
||||
val params = listOf(
|
||||
Params(1, Any::class.java, "T", "T"),
|
||||
Params(2, Z::class.java, "Z<T>", "Z<T>"),
|
||||
Params(3, Z::class.java, "Z<java.lang.String>", "Z<java.lang.String>"),
|
||||
Params(4, Any::class.java, "Zout<java.lang.String>", "X"),
|
||||
Params(5, Any::class.java, "Zin<TParam>", "Y")
|
||||
Params(2, Z::class.java, "test.Z<T>", "test.Z<T>"),
|
||||
Params(3, Z::class.java, "test.Z<java.lang.String>", "test.Z<java.lang.String>"),
|
||||
Params(4, Any::class.java, "test.Zout<java.lang.String>", "X"),
|
||||
Params(5, Any::class.java, "test.Zin<test.TParam>", "Y")
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
package test
|
||||
|
||||
class B<M>
|
||||
|
||||
@@ -17,12 +18,12 @@ interface A<T, Y : B<T>> {
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val defaultImpls = Class.forName("A\$DefaultImpls")
|
||||
val defaultImpls = Class.forName("test.A\$DefaultImpls")
|
||||
val declaredMethod = defaultImpls.getDeclaredMethod("p", A::class.java, Any::class.java)
|
||||
if (declaredMethod.toGenericString() != "public static <T_I1,Y,T,L> T A\$DefaultImpls.p(A<T_I1, Y>,T)") return "fail 1: ${declaredMethod.toGenericString()}"
|
||||
if (declaredMethod.toGenericString() != "public static <T_I1,Y,T,L> T test.A\$DefaultImpls.p(test.A<T_I1, Y>,T)") return "fail 1: ${declaredMethod.toGenericString()}"
|
||||
|
||||
val declaredProperty = defaultImpls.getDeclaredMethod("getZ", A::class.java, Any::class.java)
|
||||
if (declaredProperty.toGenericString() != "public static <T_I1,Y,T> T A\$DefaultImpls.getZ(A<T_I1, Y>,T)") return "fail 2: ${declaredProperty.toGenericString()}"
|
||||
if (declaredProperty.toGenericString() != "public static <T_I1,Y,T> T test.A\$DefaultImpls.getZ(test.A<T_I1, Y>,T)") return "fail 2: ${declaredProperty.toGenericString()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
package test
|
||||
|
||||
import kotlin.reflect.jvm.javaMethod
|
||||
import kotlin.test.assertEquals
|
||||
@@ -20,8 +21,8 @@ interface C : B2
|
||||
abstract class D : B1, C
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("public abstract void A1.a1()", D::a1.javaMethod!!.toString())
|
||||
assertEquals("public abstract void A2.a2()", D::a2.javaMethod!!.toString())
|
||||
assertEquals("public abstract void test.A1.a1()", D::a1.javaMethod!!.toString())
|
||||
assertEquals("public abstract void test.A2.a2()", D::a2.javaMethod!!.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+8
-7
@@ -1,6 +1,7 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
package test
|
||||
|
||||
import kotlin.reflect.KCallable
|
||||
import kotlin.reflect.jvm.*
|
||||
@@ -33,26 +34,26 @@ fun KCallable<*>.getJavaTypesOfParams() = parameters.map { it.type.javaType }.to
|
||||
fun KCallable<*>.getJavaTypeOfResult() = returnType.javaType.toString()
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("[class Z1]", Z1.publicXRef.getJavaTypesOfParams())
|
||||
assertEquals("int", Z1.publicXRef.getJavaTypeOfResult())
|
||||
assertEquals("[class test.Z1]", Z1.publicXRef.getJavaTypesOfParams())
|
||||
assertEquals("int", Z1.publicXRef.getJavaTypeOfResult())
|
||||
|
||||
assertEquals("[]", Z1.publicXBoundRef.getJavaTypesOfParams())
|
||||
assertEquals("int", Z1.publicXBoundRef.getJavaTypeOfResult())
|
||||
|
||||
assertEquals("[class Z2]", Z2.internalXRef.getJavaTypesOfParams())
|
||||
assertEquals("int", Z2.internalXRef.getJavaTypeOfResult())
|
||||
assertEquals("[class test.Z2]", Z2.internalXRef.getJavaTypesOfParams())
|
||||
assertEquals("int", Z2.internalXRef.getJavaTypeOfResult())
|
||||
|
||||
assertEquals("[]", Z2.internalXBoundRef.getJavaTypesOfParams())
|
||||
assertEquals("int", Z2.internalXBoundRef.getJavaTypeOfResult())
|
||||
|
||||
assertEquals("[class Z3]", Z3.privateXRef.getJavaTypesOfParams())
|
||||
assertEquals("int", Z3.privateXRef.getJavaTypeOfResult())
|
||||
assertEquals("[class test.Z3]", Z3.privateXRef.getJavaTypesOfParams())
|
||||
assertEquals("int", Z3.privateXRef.getJavaTypeOfResult())
|
||||
|
||||
assertEquals("[]", Z3.privateXBoundRef.getJavaTypesOfParams())
|
||||
assertEquals("int", Z3.privateXBoundRef.getJavaTypeOfResult())
|
||||
|
||||
|
||||
assertEquals("[class ZZ]", ZZ::x.getJavaTypesOfParams())
|
||||
assertEquals("[class test.ZZ]", ZZ::x.getJavaTypesOfParams())
|
||||
|
||||
// KT-28170
|
||||
assertEquals("int", ZZ::x.getJavaTypeOfResult())
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
package test
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@@ -11,9 +12,9 @@ class A {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("class A", "${A::class}")
|
||||
assertEquals("class A\$Nested", "${A.Nested::class}")
|
||||
assertEquals("class A\$Companion", "${A.Companion::class}")
|
||||
assertEquals("class test.A", "${A::class}")
|
||||
assertEquals("class test.A\$Nested", "${A.Nested::class}")
|
||||
assertEquals("class test.A\$Companion", "${A.Companion::class}")
|
||||
|
||||
assertEquals("class kotlin.Any", "${Any::class}")
|
||||
assertEquals("class kotlin.Int", "${Int::class}")
|
||||
|
||||
+7
-6
@@ -1,5 +1,6 @@
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR, JS, NATIVE
|
||||
// WITH_REFLECT
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -12,16 +13,16 @@ open class B<U> : A<U>()
|
||||
class C : B<String>()
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("fun A<T>.foo(T): kotlin.Unit", A<Double>::foo.toString())
|
||||
assertEquals("fun B<U>.foo(U): kotlin.Unit", B<Float>::foo.toString())
|
||||
assertEquals("fun C.foo(kotlin.String): kotlin.Unit", C::foo.toString())
|
||||
assertEquals("fun test.A<T>.foo(T): kotlin.Unit", A<Double>::foo.toString())
|
||||
assertEquals("fun test.B<U>.foo(U): kotlin.Unit", B<Float>::foo.toString())
|
||||
assertEquals("fun test.C.foo(kotlin.String): kotlin.Unit", C::foo.toString())
|
||||
|
||||
val afoo = A::class.members.single { it.name == "foo" }
|
||||
assertEquals("fun A<T>.foo(T): kotlin.Unit", afoo.toString())
|
||||
assertEquals("fun test.A<T>.foo(T): kotlin.Unit", afoo.toString())
|
||||
val bfoo = B::class.members.single { it.name == "foo" }
|
||||
assertEquals("fun B<U>.foo(U): kotlin.Unit", bfoo.toString())
|
||||
assertEquals("fun test.B<U>.foo(U): kotlin.Unit", bfoo.toString())
|
||||
val cfoo = C::class.members.single { it.name == "foo" }
|
||||
assertEquals("fun C.foo(kotlin.String): kotlin.Unit", cfoo.toString())
|
||||
assertEquals("fun test.C.foo(kotlin.String): kotlin.Unit", cfoo.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+5
-4
@@ -1,5 +1,6 @@
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR, JS, NATIVE
|
||||
// WITH_REFLECT
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -21,13 +22,13 @@ interface I3 {
|
||||
interface I : I2, I1, I3
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("fun I.f(): kotlin.Unit", I::f.toString())
|
||||
assertEquals("val I.x: kotlin.Int", I::x.toString())
|
||||
assertEquals("fun test.I.f(): kotlin.Unit", I::f.toString())
|
||||
assertEquals("val test.I.x: kotlin.Int", I::x.toString())
|
||||
|
||||
val f = I::class.members.single { it.name == "f" }
|
||||
assertEquals("fun I.f(): kotlin.Unit", f.toString())
|
||||
assertEquals("fun test.I.f(): kotlin.Unit", f.toString())
|
||||
val x = I::class.members.single { it.name == "x" }
|
||||
assertEquals("val I.x: kotlin.Int", x.toString())
|
||||
assertEquals("val test.I.x: kotlin.Int", x.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+4
-2
@@ -5,6 +5,8 @@
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.reflect.full.*
|
||||
|
||||
class A {
|
||||
@@ -17,10 +19,10 @@ class A {
|
||||
|
||||
fun box(): String {
|
||||
val p = A::class.memberExtensionProperties.single()
|
||||
return if ("$p" == "var A.(kotlin.String.)id: kotlin.String") "OK" else "Fail $p"
|
||||
return if ("$p" == "var test.A.(kotlin.String.)id: kotlin.String") "OK" else "Fail $p"
|
||||
|
||||
val q = A::class.declaredFunctions.single()
|
||||
if ("$q" != "fun A.(kotlin.Int.)foo(): kotlin.Double") return "Fail q $q"
|
||||
if ("$q" != "fun test.A.(kotlin.Int.)foo(): kotlin.Double") return "Fail q $q"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun String?.foo(x: Int, y: Array<Int>, z: IntArray, w: List<Map<Any, A<*>>>) {}
|
||||
@@ -22,7 +24,7 @@ fun box(): String {
|
||||
"kotlin.Int",
|
||||
"kotlin.Array<kotlin.Int>",
|
||||
"kotlin.IntArray",
|
||||
"kotlin.collections.List<kotlin.collections.Map<kotlin.Any, A<*>>>"
|
||||
"kotlin.collections.List<kotlin.collections.Map<kotlin.Any, test.A<*>>>"
|
||||
),
|
||||
String?::foo.parameters.map { it.type.toString() }
|
||||
)
|
||||
@@ -30,11 +32,11 @@ fun box(): String {
|
||||
assertEquals("kotlin.Unit", String?::foo.returnType.toString())
|
||||
|
||||
val bar = A::class.members.single { it.name == "bar" }
|
||||
assertEquals(listOf("A<T>", "T", "U"), bar.parameters.map { it.type.toString() })
|
||||
assertEquals(listOf("test.A<T>", "T", "U"), bar.parameters.map { it.type.toString() })
|
||||
assertEquals("T?", bar.returnType.toString())
|
||||
|
||||
assertEquals(
|
||||
listOf("A<in kotlin.Number>", "A<out kotlin.Number>"),
|
||||
listOf("test.A<in kotlin.Number>", "test.A<out kotlin.Number>"),
|
||||
::baz.parameters.map { it.type.toString() }
|
||||
)
|
||||
|
||||
|
||||
+3
-1
@@ -5,6 +5,8 @@
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A<T1> {
|
||||
@@ -16,6 +18,6 @@ class A<T1> {
|
||||
fun foo(): A<Int>.B<Double, Float>.C<Long> = null!!
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("A<kotlin.Int>.B<kotlin.Double, kotlin.Float>.C<kotlin.Long>", ::foo.returnType.toString())
|
||||
assertEquals("test.A<kotlin.Int>.B<kotlin.Double, kotlin.Float>.C<kotlin.Long>", ::foo.returnType.toString())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+3
-1
@@ -6,6 +6,8 @@
|
||||
// WITH_REFLECT
|
||||
// KT-13700 Exception obtaining descriptor for property reference
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
interface H<T> {
|
||||
@@ -15,7 +17,7 @@ interface H<T> {
|
||||
interface A : H<A>
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("A?", A::parent.returnType.toString())
|
||||
assertEquals("test.A?", A::parent.returnType.toString())
|
||||
assertEquals("T?", H<A>::parent.returnType.toString())
|
||||
|
||||
return "OK"
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -11,6 +12,6 @@ data class Box<T>(val element: T)
|
||||
|
||||
fun box(): String {
|
||||
val p = Box<String>::element
|
||||
assertEquals("val Box<T>.element: T", p.toString())
|
||||
assertEquals("val test.Box<T>.element: T", p.toString())
|
||||
return p.call(Box("OK"))
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
package test
|
||||
|
||||
import kotlin.reflect.full.createType
|
||||
import kotlin.reflect.KClass
|
||||
@@ -22,9 +23,9 @@ fun box(): String {
|
||||
fun KClass<*>.inv() = KTypeProjection.invariant(this.createType())
|
||||
|
||||
val type = A.B.C::class.createType(listOf(Long::class.inv(), Double::class.inv(), Float::class.inv(), Int::class.inv()))
|
||||
assertEquals("A<kotlin.Int>.B<kotlin.Double, kotlin.Float>.C<kotlin.Long>", type.toString())
|
||||
assertEquals("test.A<kotlin.Int>.B<kotlin.Double, kotlin.Float>.C<kotlin.Long>", type.toString())
|
||||
|
||||
assertEquals("A.D", A.D::class.createType().toString())
|
||||
assertEquals("test.A.D", A.D::class.createType().toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+5
-4
@@ -3,6 +3,7 @@
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
package test
|
||||
|
||||
import kotlin.reflect.full.createType
|
||||
import kotlin.reflect.KTypeProjection
|
||||
@@ -12,11 +13,11 @@ class Foo
|
||||
class Bar<T>
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Foo", Foo::class.createType().toString())
|
||||
assertEquals("Foo?", Foo::class.createType(nullable = true).toString())
|
||||
assertEquals("test.Foo", Foo::class.createType().toString())
|
||||
assertEquals("test.Foo?", Foo::class.createType(nullable = true).toString())
|
||||
|
||||
assertEquals("Bar<kotlin.String>", Bar::class.createType(listOf(KTypeProjection.invariant(String::class.createType()))).toString())
|
||||
assertEquals("Bar<kotlin.Int>?", Bar::class.createType(listOf(KTypeProjection.invariant(Int::class.createType())), nullable = true).toString())
|
||||
assertEquals("test.Bar<kotlin.String>", Bar::class.createType(listOf(KTypeProjection.invariant(String::class.createType()))).toString())
|
||||
assertEquals("test.Bar<kotlin.Int>?", Bar::class.createType(listOf(KTypeProjection.invariant(Int::class.createType())), nullable = true).toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
abstract class A<R> {
|
||||
@@ -20,6 +22,6 @@ inline fun<reified T> foo(): A<T> {
|
||||
fun box(): String {
|
||||
val y = foo<String>();
|
||||
assertEquals("OK", y.f())
|
||||
assertEquals("A<java.lang.String>", y.javaClass.getGenericSuperclass()?.toString())
|
||||
assertEquals("test.A<java.lang.String>", y.javaClass.getGenericSuperclass()?.toString())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
|
||||
// WITH_RUNTIME
|
||||
// Basically this test checks that no captured type used as argument for signature mapping
|
||||
|
||||
package test
|
||||
|
||||
class SwOperator<T>: Operator<List<T>, T>
|
||||
|
||||
interface Operator<R, T>
|
||||
|
||||
open class Inv<T>
|
||||
|
||||
class Obs<Y> {
|
||||
inline fun <reified X> lift(lift: Operator<out X, in Y>) = object : Inv<X>() {}
|
||||
}
|
||||
@@ -19,7 +21,7 @@ fun box(): String {
|
||||
val inv = o.lift(SwOperator())
|
||||
val signature = inv.javaClass.genericSuperclass.toString()
|
||||
|
||||
if (signature != "Inv<java.util.List<? extends java.lang.CharSequence>>") return "fail 1: $signature"
|
||||
if (signature != "test.Inv<java.util.List<? extends java.lang.CharSequence>>") return "fail 1: $signature"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_RUNTIME
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -27,6 +28,6 @@ inline fun<reified T> foo(): G {
|
||||
fun box(): String {
|
||||
val y = foo<String>().bar();
|
||||
assertEquals("OK", y.toString())
|
||||
assertEquals("A<java.lang.String>", y.javaClass.getGenericSuperclass()?.toString())
|
||||
assertEquals("test.A<java.lang.String>", y.javaClass.getGenericSuperclass()?.toString())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
open class A<T1, T2, T3>
|
||||
@@ -27,7 +29,7 @@ fun box(): String {
|
||||
Triple("java.lang.Integer", "java.lang.Double", "java.lang.Integer"),
|
||||
Triple("java.lang.Boolean", "java.lang.Double", "java.lang.Integer"),
|
||||
Triple("java.lang.Double", "java.lang.Boolean", "java.lang.Integer")
|
||||
).map { "A<${it.first}, ${it.second}, ${it.third}>" }
|
||||
).map { "test.A<${it.first}, ${it.second}, ${it.third}>" }
|
||||
|
||||
for (i in expected.indices) {
|
||||
assertEquals(expected[i], result[i].javaClass.getGenericSuperclass()?.toString(), "$i-th element")
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_RUNTIME
|
||||
package test
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -34,7 +35,7 @@ fun box(): String {
|
||||
val x2 = res.second.bar()
|
||||
assertEquals("OK", x1.toString())
|
||||
assertEquals("OK", x2.toString())
|
||||
assertEquals("A<java.lang.Integer>", x1.javaClass.getGenericSuperclass()?.toString())
|
||||
assertEquals("A<java.lang.String>", x2.javaClass.getGenericSuperclass()?.toString())
|
||||
assertEquals("test.A<java.lang.Integer>", x1.javaClass.getGenericSuperclass()?.toString())
|
||||
assertEquals("test.A<java.lang.String>", x2.javaClass.getGenericSuperclass()?.toString())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+3
-1
@@ -2,6 +2,7 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// FILE: Foo.kt
|
||||
package foo
|
||||
|
||||
class A2 {
|
||||
fun doWork(job: () -> Unit) {
|
||||
@@ -10,6 +11,7 @@ class A2 {
|
||||
}
|
||||
|
||||
// FILE: kt17091.kt
|
||||
import foo.A2
|
||||
|
||||
typealias Z = String
|
||||
|
||||
@@ -25,7 +27,7 @@ fun box(): String {
|
||||
|
||||
if (java.lang.Class.forName("Kt17091Kt\$sam\$java_lang_Runnable$0") == null) return "fail: can't find sam wrapper"
|
||||
|
||||
if (java.lang.Class.forName("A2\$sam\$java_lang_Runnable$0") == null) return "fail 2: can't find sam wrapper"
|
||||
if (java.lang.Class.forName("foo.A2\$sam\$java_lang_Runnable$0") == null) return "fail 2: can't find sam wrapper"
|
||||
|
||||
return result
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
package test
|
||||
|
||||
interface Z{
|
||||
|
||||
private fun extension(): String {
|
||||
@@ -14,7 +16,7 @@ object Z2 : Z {
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val size = Class.forName("Z2").declaredMethods.size
|
||||
val size = Class.forName("test.Z2").declaredMethods.size
|
||||
if (size != 0) return "fail: $size"
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user