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
|
||||
|
||||
fun test(f: Function<*>, arity: Int) {
|
||||
assertEquals(arity, (f as FunctionBase).getArity())
|
||||
assertEquals(arity, (f as FunctionBase).arity)
|
||||
}
|
||||
|
||||
fun foo(s: String, i: Int) {}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ suspend fun builder(c: suspend () -> Unit) {
|
||||
}
|
||||
|
||||
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) {}
|
||||
|
||||
@@ -37,7 +37,7 @@ internal class KFunctionImpl private constructor(
|
||||
private val signature: String,
|
||||
descriptorInitialValue: FunctionDescriptor?,
|
||||
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?)
|
||||
: this(container, name, signature, null, boundReceiver)
|
||||
|
||||
@@ -143,7 +143,7 @@ internal class KFunctionImpl private constructor(
|
||||
private fun createConstructorCaller(member: Constructor<*>) =
|
||||
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
|
||||
get() = descriptor.isInline
|
||||
|
||||
+5
-9
@@ -132,13 +132,11 @@ internal interface SuspendFunction
|
||||
@SinceKotlin("1.3")
|
||||
// Restricted suspension lambdas inherit from this class
|
||||
internal abstract class RestrictedSuspendLambda(
|
||||
private val arity: Int,
|
||||
public override val arity: Int,
|
||||
completion: Continuation<Any?>?
|
||||
) : RestrictedContinuationImpl(completion), FunctionBase, SuspendFunction {
|
||||
) : RestrictedContinuationImpl(completion), FunctionBase<Any?>, SuspendFunction {
|
||||
constructor(arity: Int) : this(arity, null)
|
||||
|
||||
public override fun getArity(): Int = arity
|
||||
|
||||
public override fun toString(): String =
|
||||
if (completion == null)
|
||||
Reflection.renderLambdaToString(this) // this is lambda
|
||||
@@ -149,16 +147,14 @@ internal abstract class RestrictedSuspendLambda(
|
||||
@SinceKotlin("1.3")
|
||||
// Suspension lambdas inherit from this class
|
||||
internal abstract class SuspendLambda(
|
||||
private val arity: Int,
|
||||
public override val arity: Int,
|
||||
completion: Continuation<Any?>?
|
||||
) : ContinuationImpl(completion), FunctionBase, SuspendFunction {
|
||||
) : ContinuationImpl(completion), FunctionBase<Any?>, SuspendFunction {
|
||||
constructor(arity: Int) : this(arity, null)
|
||||
|
||||
public override fun getArity(): Int = arity
|
||||
|
||||
public override fun toString(): String =
|
||||
if (completion == null)
|
||||
Reflection.renderLambdaToString(this) // this is lambda
|
||||
else
|
||||
super.toString() // this is continuation
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -3,10 +3,8 @@
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlin.jvm.internal;
|
||||
package kotlin.jvm.internal
|
||||
|
||||
import kotlin.Function;
|
||||
|
||||
public interface FunctionBase extends Function {
|
||||
int getArity();
|
||||
interface FunctionBase<out R> : Function<R> {
|
||||
val arity: Int
|
||||
}
|
||||
@@ -7,8 +7,6 @@ package kotlin.jvm.internal
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
abstract class Lambda(private val arity: Int) : FunctionBase, Serializable {
|
||||
override fun getArity(): Int = arity
|
||||
|
||||
abstract class Lambda<out R>(override val arity: Int) : FunctionBase<R>, Serializable {
|
||||
override fun toString(): String = Reflection.renderLambdaToString(this)
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ abstract class CoroutineImpl(
|
||||
arity: Int,
|
||||
@JvmField
|
||||
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 == 0 in initial part of the coroutine
|
||||
|
||||
Reference in New Issue
Block a user