@@ -1817,7 +1817,7 @@ open class KotlinFileExtractor(
18171817 }
18181818
18191819 private fun getDefaultsMethodLabel (f : IrFunction ): Label <out DbCallable > {
1820- val defaultsMethodName = getDefaultsMethodName(f)
1820+ val defaultsMethodName = if (f is IrConstructor ) " <init> " else getDefaultsMethodName(f)
18211821 val normalArgTypes = getDefaultsMethodArgTypes(f)
18221822 val extensionParamType = f.extensionReceiverParameter?.let { erase(it.type) }
18231823
@@ -1969,6 +1969,15 @@ open class KotlinFileExtractor(
19691969 target
19701970 }
19711971
1972+ private fun callUsesDefaultArguments (callTarget : IrFunction , valueArguments : List <IrExpression ?>): Boolean {
1973+ val varargParam = callTarget.valueParameters.withIndex().find { it.value.isVararg }
1974+ // If the vararg param is the only one not specified, and it has no default value, then we don't need to call a $default method,
1975+ // as omitting it already implies passing an empty vararg array.
1976+ val nullAllowedIdx = if (varargParam != null && varargParam.value.defaultValue == null ) varargParam.index else - 1
1977+ return valueArguments.withIndex().any { (index, it) -> it == null && index != nullAllowedIdx }
1978+ }
1979+
1980+
19721981 fun extractRawMethodAccess (
19731982 syntacticCallTarget : IrFunction ,
19741983 locElement : IrElement ,
@@ -1985,12 +1994,8 @@ open class KotlinFileExtractor(
19851994 superQualifierSymbol : IrClassSymbol ? = null) {
19861995
19871996 val locId = tw.getLocation(locElement)
1988- val varargParam = syntacticCallTarget.valueParameters.withIndex().find { it.value.isVararg }
1989- // If the vararg param is the only one not specified, and it has no default value, then we don't need to call a $default method,
1990- // as omitting it already implies passing an empty vararg array.
1991- val nullAllowedIdx = if (varargParam != null && varargParam.value.defaultValue == null ) varargParam.index else - 1
19921997
1993- if (valueArguments.withIndex().any { (index, it) -> it == null && index != nullAllowedIdx } ) {
1998+ if (callUsesDefaultArguments(syntacticCallTarget, valueArguments) ) {
19941999 extractsDefaultsCall(
19952000 syntacticCallTarget,
19962001 locId,
@@ -3060,8 +3065,7 @@ open class KotlinFileExtractor(
30603065 val valueArgs = (0 until e.valueArgumentsCount).map { e.getValueArgument(it) }
30613066 // For now, don't try to use default methods for enum constructor calls,
30623067 // which have null arguments even though the parameters don't give default values.
3063- val anyDefaultArgs = e !is IrEnumConstructorCall && valueArgs.any { it == null }
3064- val id = if (anyDefaultArgs) {
3068+ val id = if (callUsesDefaultArguments(e.symbol.owner, valueArgs)) {
30653069 extractNewExpr(getDefaultsMethodLabel(e.symbol.owner).cast(), type, locId, parent, idx, callable, enclosingStmt).also {
30663070 extractDefaultsCallArguments(it, e.symbol.owner, callable, enclosingStmt, valueArgs, null , null )
30673071 }
0 commit comments