@@ -1809,7 +1809,7 @@ open class KotlinFileExtractor(
18091809 }
18101810
18111811 private fun getDefaultsMethodLabel (f : IrFunction ): Label <out DbCallable > {
1812- val defaultsMethodName = getDefaultsMethodName(f)
1812+ val defaultsMethodName = if (f is IrConstructor ) " <init> " else getDefaultsMethodName(f)
18131813 val normalArgTypes = getDefaultsMethodArgTypes(f)
18141814 val extensionParamType = f.extensionReceiverParameter?.let { erase(it.type) }
18151815
@@ -1961,6 +1961,15 @@ open class KotlinFileExtractor(
19611961 target
19621962 }
19631963
1964+ private fun callUsesDefaultArguments (callTarget : IrFunction , valueArguments : List <IrExpression ?>): Boolean {
1965+ val varargParam = callTarget.valueParameters.withIndex().find { it.value.isVararg }
1966+ // 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,
1967+ // as omitting it already implies passing an empty vararg array.
1968+ val nullAllowedIdx = if (varargParam != null && varargParam.value.defaultValue == null ) varargParam.index else - 1
1969+ return valueArguments.withIndex().any { (index, it) -> it == null && index != nullAllowedIdx }
1970+ }
1971+
1972+
19641973 fun extractRawMethodAccess (
19651974 syntacticCallTarget : IrFunction ,
19661975 locElement : IrElement ,
@@ -1977,12 +1986,8 @@ open class KotlinFileExtractor(
19771986 superQualifierSymbol : IrClassSymbol ? = null) {
19781987
19791988 val locId = tw.getLocation(locElement)
1980- val varargParam = syntacticCallTarget.valueParameters.withIndex().find { it.value.isVararg }
1981- // 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,
1982- // as omitting it already implies passing an empty vararg array.
1983- val nullAllowedIdx = if (varargParam != null && varargParam.value.defaultValue == null ) varargParam.index else - 1
19841989
1985- if (valueArguments.withIndex().any { (index, it) -> it == null && index != nullAllowedIdx } ) {
1990+ if (callUsesDefaultArguments(syntacticCallTarget, valueArguments) ) {
19861991 extractsDefaultsCall(
19871992 syntacticCallTarget,
19881993 locId,
@@ -3034,8 +3039,7 @@ open class KotlinFileExtractor(
30343039 val valueArgs = (0 until e.valueArgumentsCount).map { e.getValueArgument(it) }
30353040 // For now, don't try to use default methods for enum constructor calls,
30363041 // which have null arguments even though the parameters don't give default values.
3037- val anyDefaultArgs = e !is IrEnumConstructorCall && valueArgs.any { it == null }
3038- val id = if (anyDefaultArgs) {
3042+ val id = if (e !is IrEnumConstructorCall && callUsesDefaultArguments(e.symbol.owner, valueArgs)) {
30393043 extractNewExpr(getDefaultsMethodLabel(e.symbol.owner).cast(), type, locId, parent, idx, callable, enclosingStmt).also {
30403044 extractDefaultsCallArguments(it, e.symbol.owner, callable, enclosingStmt, valueArgs, null , null )
30413045 }
0 commit comments