Support isSubtypeOf check for functional type
This commit is contained in:
committed by
TeamCityServer
parent
c1aa39065f
commit
cc0bbac354
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.ir.declarations.IrClass
|
|||||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||||
import org.jetbrains.kotlin.ir.interpreter.exceptions.throwAsUserException
|
import org.jetbrains.kotlin.ir.interpreter.exceptions.throwAsUserException
|
||||||
|
import org.jetbrains.kotlin.ir.interpreter.isFunction
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
import org.jetbrains.kotlin.ir.util.defaultType
|
import org.jetbrains.kotlin.ir.util.defaultType
|
||||||
@@ -55,6 +56,13 @@ internal fun State.isSubtypeOf(other: IrType): Boolean {
|
|||||||
return thisClass.isSubtypeOfClass(otherArgument.typeOrNull!!.classOrNull!!)
|
return thisClass.isSubtypeOfClass(otherArgument.typeOrNull!!.classOrNull!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this is Lambda) {
|
||||||
|
if (!other.isFunction()) return false
|
||||||
|
val typeArgumentsCount = (other as? IrSimpleType)?.arguments?.size ?: return false
|
||||||
|
val lambdaArgumentCount = this.irFunction.valueParameters.size + 1 // +1 for return type
|
||||||
|
return typeArgumentsCount == lambdaArgumentCount
|
||||||
|
}
|
||||||
|
|
||||||
return this.irClass.defaultType.isSubtypeOfClass(other.classOrNull!!)
|
return this.irClass.defaultType.isSubtypeOfClass(other.classOrNull!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user