Add test checking argument <-> parameter matching, and fix superconstructor calls that were missing their argument.

This commit is contained in:
Chris Smowton
2022-10-13 14:47:36 +01:00
parent f1fd470f49
commit 4c63237ed1
4 changed files with 34 additions and 4 deletions

View File

@@ -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) {