mirror of
https://github.com/github/codeql.git
synced 2025-12-20 18:56:32 +01:00
Merge pull request #10473 from tamasvajk/kotlin-suspend
Kotlin: Extract `suspend` functions
This commit is contained in:
@@ -917,6 +917,9 @@ open class KotlinFileExtractor(
|
||||
if (f is IrSimpleFunction && f.overriddenSymbols.isNotEmpty()) {
|
||||
addModifiers(id, "override")
|
||||
}
|
||||
if (f.isSuspend) {
|
||||
addModifiers(id, "suspend")
|
||||
}
|
||||
|
||||
return id
|
||||
}
|
||||
@@ -1468,7 +1471,7 @@ open class KotlinFileExtractor(
|
||||
|
||||
val (isFunctionInvoke, isBigArityFunctionInvoke) =
|
||||
if (drType is IrSimpleType &&
|
||||
drType.isFunctionOrKFunction() &&
|
||||
(drType.isFunctionOrKFunction() || drType.isSuspendFunctionOrKFunction()) &&
|
||||
callTarget.name.asString() == OperatorNameConventions.INVOKE.asString()) {
|
||||
Pair(true, drType.arguments.size > BuiltInFunctionArity.BIG_ARITY)
|
||||
} else {
|
||||
@@ -4523,17 +4526,17 @@ open class KotlinFileExtractor(
|
||||
```
|
||||
*/
|
||||
|
||||
if (!e.argument.type.isFunctionOrKFunction()) {
|
||||
logger.errorElement("Expected to find expression with function type in SAM conversion.", e)
|
||||
return
|
||||
}
|
||||
|
||||
val st = e.argument.type as? IrSimpleType
|
||||
if (st == null) {
|
||||
logger.errorElement("Expected to find a simple type in SAM conversion.", e)
|
||||
return
|
||||
}
|
||||
|
||||
if (!st.isFunctionOrKFunction() && !st.isSuspendFunctionOrKFunction()) {
|
||||
logger.errorElement("Expected to find expression with function type in SAM conversion.", e)
|
||||
return
|
||||
}
|
||||
|
||||
// Either Function1, ... Function22 or FunctionN type, but not Function23 or above.
|
||||
val functionType = getFunctionalInterfaceTypeWithTypeArgs(st.arguments)
|
||||
if (functionType == null) {
|
||||
@@ -4596,6 +4599,10 @@ open class KotlinFileExtractor(
|
||||
// the real underlying R Function<T, R>.apply(T t).
|
||||
forceExtractFunction(samMember, classId, extractBody = false, extractMethodAndParameterTypeAccesses = true, typeSub, classTypeArgs, ids.function, tw.getLocation(e))
|
||||
|
||||
if (st.isSuspendFunctionOrKFunction()) {
|
||||
addModifiers(ids.function, "suspend")
|
||||
}
|
||||
|
||||
//body
|
||||
val blockId = tw.getFreshIdLabel<DbBlock>()
|
||||
tw.writeStmts_block(blockId, ids.function, 0, ids.function)
|
||||
|
||||
Reference in New Issue
Block a user