mirror of
https://github.com/github/codeql.git
synced 2025-12-22 11:46:32 +01:00
Add test checking argument <-> parameter matching, and fix superconstructor calls that were missing their argument.
This commit is contained in:
@@ -4496,7 +4496,10 @@ open class KotlinFileExtractor(
|
||||
val baseClass = pluginContext.referenceClass(FqName("kotlin.jvm.internal.FunctionReference"))?.owner?.typeWith()
|
||||
?: pluginContext.irBuiltIns.anyType
|
||||
|
||||
val classId = extractGeneratedClass(ids, listOf(baseClass, fnInterfaceType), locId, functionReferenceExpr, declarationParent)
|
||||
val classId = extractGeneratedClass(ids, listOf(baseClass, fnInterfaceType), locId, functionReferenceExpr, declarationParent, { it.valueParameters.size == 1 }) {
|
||||
// The argument to FunctionReference's constructor is the function arity.
|
||||
extractConstantInteger(type.arguments.size - 1, locId, it, 0, ids.constructor, it)
|
||||
}
|
||||
|
||||
helper.extractReceiverField()
|
||||
|
||||
@@ -5236,7 +5239,9 @@ open class KotlinFileExtractor(
|
||||
superTypes: List<IrType>,
|
||||
locId: Label<DbLocation>,
|
||||
elementToReportOn: IrElement,
|
||||
declarationParent: IrDeclarationParent
|
||||
declarationParent: IrDeclarationParent,
|
||||
superConstructorSelector: (IrFunction) -> Boolean = { it.valueParameters.isEmpty() },
|
||||
extractSuperconstructorArgs: (Label<DbSuperconstructorinvocationstmt>) -> Unit = {}
|
||||
): Label<out DbClass> {
|
||||
// Write class
|
||||
val id = ids.type.javaResult.id.cast<DbClass>()
|
||||
@@ -5261,7 +5266,7 @@ open class KotlinFileExtractor(
|
||||
if (baseClass == null) {
|
||||
logger.warnElement("Cannot find base class", elementToReportOn)
|
||||
} else {
|
||||
val baseConstructor = baseClass.owner.declarations.findSubType<IrFunction> { it.symbol is IrConstructorSymbol }
|
||||
val baseConstructor = baseClass.owner.declarations.findSubType<IrFunction> { it.symbol is IrConstructorSymbol && superConstructorSelector(it) }
|
||||
if (baseConstructor == null) {
|
||||
logger.warnElement("Cannot find base constructor", elementToReportOn)
|
||||
} else {
|
||||
@@ -5272,6 +5277,7 @@ open class KotlinFileExtractor(
|
||||
|
||||
tw.writeHasLocation(superCallId, locId)
|
||||
tw.writeCallableBinding(superCallId.cast<DbCaller>(), baseConstructorId)
|
||||
extractSuperconstructorArgs(superCallId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5285,7 +5291,7 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the class around a local function or a lambda.
|
||||
* Extracts the class around a local function or a lambda. The superclass must have a no-arg constructor.
|
||||
*/
|
||||
private fun extractGeneratedClass(localFunction: IrFunction, superTypes: List<IrType>) : Label<out DbClass> {
|
||||
with("generated class", localFunction) {
|
||||
|
||||
Reference in New Issue
Block a user