@@ -1817,7 +1817,7 @@ open class KotlinFileExtractor(
1817
1817
}
1818
1818
1819
1819
private fun getDefaultsMethodLabel (f : IrFunction ): Label <out DbCallable > {
1820
- val defaultsMethodName = getDefaultsMethodName(f)
1820
+ val defaultsMethodName = if (f is IrConstructor ) " <init> " else getDefaultsMethodName(f)
1821
1821
val normalArgTypes = getDefaultsMethodArgTypes(f)
1822
1822
val extensionParamType = f.extensionReceiverParameter?.let { erase(it.type) }
1823
1823
@@ -1969,6 +1969,15 @@ open class KotlinFileExtractor(
1969
1969
target
1970
1970
}
1971
1971
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
+
1972
1981
fun extractRawMethodAccess (
1973
1982
syntacticCallTarget : IrFunction ,
1974
1983
locElement : IrElement ,
@@ -1985,12 +1994,8 @@ open class KotlinFileExtractor(
1985
1994
superQualifierSymbol : IrClassSymbol ? = null) {
1986
1995
1987
1996
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
1992
1997
1993
- if (valueArguments.withIndex().any { (index, it) -> it == null && index != nullAllowedIdx } ) {
1998
+ if (callUsesDefaultArguments(syntacticCallTarget, valueArguments) ) {
1994
1999
extractsDefaultsCall(
1995
2000
syntacticCallTarget,
1996
2001
locId,
@@ -3060,8 +3065,7 @@ open class KotlinFileExtractor(
3060
3065
val valueArgs = (0 until e.valueArgumentsCount).map { e.getValueArgument(it) }
3061
3066
// For now, don't try to use default methods for enum constructor calls,
3062
3067
// 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)) {
3065
3069
extractNewExpr(getDefaultsMethodLabel(e.symbol.owner).cast(), type, locId, parent, idx, callable, enclosingStmt).also {
3066
3070
extractDefaultsCallArguments(it, e.symbol.owner, callable, enclosingStmt, valueArgs, null , null )
3067
3071
}
0 commit comments