Convert FunctionBase to Kotlin, add type parameter to Lambda
This will make it possible to avoid raw types when inheriting from both FunctionBase and Function<R>. This change adds a generic type parameter to FunctionBase and Lambda which is not source-breaking under our policy because both FunctionBase and Lambda are internal classes (located in package kotlin.jvm.internal)
This commit is contained in:
committed by
Ilya Gorbunov
parent
e35ebff4e1
commit
51979b9ffa
+1
-1
@@ -9,7 +9,7 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.jvm.internal.FunctionBase
|
import kotlin.jvm.internal.FunctionBase
|
||||||
|
|
||||||
fun test(f: Function<*>, arity: Int) {
|
fun test(f: Function<*>, arity: Int) {
|
||||||
assertEquals(arity, (f as FunctionBase).getArity())
|
assertEquals(arity, (f as FunctionBase).arity)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun foo(s: String, i: Int) {}
|
fun foo(s: String, i: Int) {}
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ suspend fun builder(c: suspend () -> Unit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun test(f: Function<*>, arity: Int) {
|
fun test(f: Function<*>, arity: Int) {
|
||||||
assertEquals(arity, (f as FunctionBase).getArity())
|
assertEquals(arity, (f as FunctionBase).arity)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun foo(s: String, i: Int) {}
|
suspend fun foo(s: String, i: Int) {}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ internal class KFunctionImpl private constructor(
|
|||||||
private val signature: String,
|
private val signature: String,
|
||||||
descriptorInitialValue: FunctionDescriptor?,
|
descriptorInitialValue: FunctionDescriptor?,
|
||||||
private val boundReceiver: Any? = CallableReference.NO_RECEIVER
|
private val boundReceiver: Any? = CallableReference.NO_RECEIVER
|
||||||
) : KCallableImpl<Any?>(), KFunction<Any?>, FunctionBase, FunctionWithAllInvokes {
|
) : KCallableImpl<Any?>(), KFunction<Any?>, FunctionBase<Any?>, FunctionWithAllInvokes {
|
||||||
constructor(container: KDeclarationContainerImpl, name: String, signature: String, boundReceiver: Any?)
|
constructor(container: KDeclarationContainerImpl, name: String, signature: String, boundReceiver: Any?)
|
||||||
: this(container, name, signature, null, boundReceiver)
|
: this(container, name, signature, null, boundReceiver)
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ internal class KFunctionImpl private constructor(
|
|||||||
private fun createConstructorCaller(member: Constructor<*>) =
|
private fun createConstructorCaller(member: Constructor<*>) =
|
||||||
if (isBound) FunctionCaller.BoundConstructor(member, boundReceiver) else FunctionCaller.Constructor(member)
|
if (isBound) FunctionCaller.BoundConstructor(member, boundReceiver) else FunctionCaller.Constructor(member)
|
||||||
|
|
||||||
override fun getArity() = caller.arity
|
override val arity: Int get() = caller.arity
|
||||||
|
|
||||||
override val isInline: Boolean
|
override val isInline: Boolean
|
||||||
get() = descriptor.isInline
|
get() = descriptor.isInline
|
||||||
|
|||||||
+5
-9
@@ -132,13 +132,11 @@ internal interface SuspendFunction
|
|||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
// Restricted suspension lambdas inherit from this class
|
// Restricted suspension lambdas inherit from this class
|
||||||
internal abstract class RestrictedSuspendLambda(
|
internal abstract class RestrictedSuspendLambda(
|
||||||
private val arity: Int,
|
public override val arity: Int,
|
||||||
completion: Continuation<Any?>?
|
completion: Continuation<Any?>?
|
||||||
) : RestrictedContinuationImpl(completion), FunctionBase, SuspendFunction {
|
) : RestrictedContinuationImpl(completion), FunctionBase<Any?>, SuspendFunction {
|
||||||
constructor(arity: Int) : this(arity, null)
|
constructor(arity: Int) : this(arity, null)
|
||||||
|
|
||||||
public override fun getArity(): Int = arity
|
|
||||||
|
|
||||||
public override fun toString(): String =
|
public override fun toString(): String =
|
||||||
if (completion == null)
|
if (completion == null)
|
||||||
Reflection.renderLambdaToString(this) // this is lambda
|
Reflection.renderLambdaToString(this) // this is lambda
|
||||||
@@ -149,16 +147,14 @@ internal abstract class RestrictedSuspendLambda(
|
|||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
// Suspension lambdas inherit from this class
|
// Suspension lambdas inherit from this class
|
||||||
internal abstract class SuspendLambda(
|
internal abstract class SuspendLambda(
|
||||||
private val arity: Int,
|
public override val arity: Int,
|
||||||
completion: Continuation<Any?>?
|
completion: Continuation<Any?>?
|
||||||
) : ContinuationImpl(completion), FunctionBase, SuspendFunction {
|
) : ContinuationImpl(completion), FunctionBase<Any?>, SuspendFunction {
|
||||||
constructor(arity: Int) : this(arity, null)
|
constructor(arity: Int) : this(arity, null)
|
||||||
|
|
||||||
public override fun getArity(): Int = arity
|
|
||||||
|
|
||||||
public override fun toString(): String =
|
public override fun toString(): String =
|
||||||
if (completion == null)
|
if (completion == null)
|
||||||
Reflection.renderLambdaToString(this) // this is lambda
|
Reflection.renderLambdaToString(this) // this is lambda
|
||||||
else
|
else
|
||||||
super.toString() // this is continuation
|
super.toString() // this is continuation
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-5
@@ -3,10 +3,8 @@
|
|||||||
* that can be found in the license/LICENSE.txt file.
|
* that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package kotlin.jvm.internal;
|
package kotlin.jvm.internal
|
||||||
|
|
||||||
import kotlin.Function;
|
interface FunctionBase<out R> : Function<R> {
|
||||||
|
val arity: Int
|
||||||
public interface FunctionBase extends Function {
|
|
||||||
int getArity();
|
|
||||||
}
|
}
|
||||||
@@ -7,8 +7,6 @@ package kotlin.jvm.internal
|
|||||||
|
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
abstract class Lambda(private val arity: Int) : FunctionBase, Serializable {
|
abstract class Lambda<out R>(override val arity: Int) : FunctionBase<R>, Serializable {
|
||||||
override fun getArity(): Int = arity
|
|
||||||
|
|
||||||
override fun toString(): String = Reflection.renderLambdaToString(this)
|
override fun toString(): String = Reflection.renderLambdaToString(this)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ abstract class CoroutineImpl(
|
|||||||
arity: Int,
|
arity: Int,
|
||||||
@JvmField
|
@JvmField
|
||||||
protected var completion: Continuation<Any?>?
|
protected var completion: Continuation<Any?>?
|
||||||
) : Lambda(arity), Continuation<Any?> {
|
) : Lambda<Any?>(arity), Continuation<Any?> {
|
||||||
|
|
||||||
// label == -1 when coroutine cannot be started (it is just a factory object) or has already finished execution
|
// label == -1 when coroutine cannot be started (it is just a factory object) or has already finished execution
|
||||||
// label == 0 in initial part of the coroutine
|
// label == 0 in initial part of the coroutine
|
||||||
|
|||||||
Reference in New Issue
Block a user