Use manual type mapping in reflection for members from built-ins
There are cases when members deserialized from JVM classes have no JVM signature in the proto. For example, if a member is inherited from a built-in class (such as Map.getOrDefault in some Map implementations), or if a member is synthesized in the compiler front-end and back-end separately (such as enum values/valueOf). In these cases, we'll use the naive type mapping to try to recover the signature. #KT-16616 Fixed #KT-17542 Fixed
This commit is contained in:
+18
-17
@@ -18,26 +18,27 @@ import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
fun FunctionDescriptor.computeJvmDescriptor(withReturnType: Boolean = true)
|
||||
= StringBuilder().apply {
|
||||
append(if (this@computeJvmDescriptor is ConstructorDescriptor) "<init>" else name.asString())
|
||||
append("(")
|
||||
fun FunctionDescriptor.computeJvmDescriptor(withReturnType: Boolean = true, withName: Boolean = true): String = buildString {
|
||||
if (withName) {
|
||||
append(if (this@computeJvmDescriptor is ConstructorDescriptor) "<init>" else name.asString())
|
||||
}
|
||||
|
||||
valueParameters.forEach {
|
||||
appendErasedType(it.type)
|
||||
}
|
||||
append("(")
|
||||
|
||||
append(")")
|
||||
for (parameter in valueParameters) {
|
||||
appendErasedType(parameter.type)
|
||||
}
|
||||
|
||||
if (withReturnType) {
|
||||
if (hasVoidReturnType(this@computeJvmDescriptor)) {
|
||||
append("V")
|
||||
}
|
||||
else {
|
||||
appendErasedType(returnType!!)
|
||||
}
|
||||
}
|
||||
}.toString()
|
||||
append(")")
|
||||
|
||||
if (withReturnType) {
|
||||
if (hasVoidReturnType(this@computeJvmDescriptor)) {
|
||||
append("V")
|
||||
} else {
|
||||
appendErasedType(returnType!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Boxing is only necessary for 'remove(E): Boolean' of a MutableCollection<Int> implementation
|
||||
// Otherwise this method might clash with 'remove(I): E' defined in the java.util.List JDK interface (mapped to kotlin 'removeAt')
|
||||
|
||||
Reference in New Issue
Block a user