@@ -1809,7 +1809,7 @@ open class KotlinFileExtractor(
1809
1809
}
1810
1810
1811
1811
private fun getDefaultsMethodLabel (f : IrFunction ): Label <out DbCallable > {
1812
- val defaultsMethodName = getDefaultsMethodName(f)
1812
+ val defaultsMethodName = if (f is IrConstructor ) " <init> " else getDefaultsMethodName(f)
1813
1813
val normalArgTypes = getDefaultsMethodArgTypes(f)
1814
1814
val extensionParamType = f.extensionReceiverParameter?.let { erase(it.type) }
1815
1815
@@ -1961,6 +1961,15 @@ open class KotlinFileExtractor(
1961
1961
target
1962
1962
}
1963
1963
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
+
1964
1973
fun extractRawMethodAccess (
1965
1974
syntacticCallTarget : IrFunction ,
1966
1975
locElement : IrElement ,
@@ -1977,12 +1986,8 @@ open class KotlinFileExtractor(
1977
1986
superQualifierSymbol : IrClassSymbol ? = null) {
1978
1987
1979
1988
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
1984
1989
1985
- if (valueArguments.withIndex().any { (index, it) -> it == null && index != nullAllowedIdx } ) {
1990
+ if (callUsesDefaultArguments(syntacticCallTarget, valueArguments) ) {
1986
1991
extractsDefaultsCall(
1987
1992
syntacticCallTarget,
1988
1993
locId,
@@ -3034,8 +3039,7 @@ open class KotlinFileExtractor(
3034
3039
val valueArgs = (0 until e.valueArgumentsCount).map { e.getValueArgument(it) }
3035
3040
// For now, don't try to use default methods for enum constructor calls,
3036
3041
// 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)) {
3039
3043
extractNewExpr(getDefaultsMethodLabel(e.symbol.owner).cast(), type, locId, parent, idx, callable, enclosingStmt).also {
3040
3044
extractDefaultsCallArguments(it, e.symbol.owner, callable, enclosingStmt, valueArgs, null , null )
3041
3045
}
0 commit comments