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
+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