@@ -1868,12 +1868,13 @@ open class KotlinFileExtractor(
1868
1868
extractStaticTypeAccessQualifierUnchecked(overriddenCallTarget.parent, id, locId, enclosingCallable, enclosingStmt)
1869
1869
}
1870
1870
1871
- extractDefaultsCallArguments(id, overriddenCallTarget, enclosingCallable, enclosingStmt, valueArguments, dispatchReceiver, extensionReceiver)
1871
+ extractDefaultsCallArguments(id, overriddenCallTarget, locId, enclosingCallable, enclosingStmt, valueArguments, dispatchReceiver, extensionReceiver)
1872
1872
}
1873
1873
1874
1874
private fun extractDefaultsCallArguments (
1875
1875
id : Label <out DbExprparent >,
1876
1876
callTarget : IrFunction ,
1877
+ locId : Label <DbLocation >,
1877
1878
enclosingCallable : Label <out DbCallable >,
1878
1879
enclosingStmt : Label <out DbStmt >,
1879
1880
valueArguments : List <IrExpression ?>,
@@ -1900,7 +1901,7 @@ open class KotlinFileExtractor(
1900
1901
IrConstImpl .defaultValueForType(0 , 0 , getDefaultsMethodLastArgType(callTarget))
1901
1902
)
1902
1903
1903
- extractCallValueArguments(id, valueArgsWithDummies + extraArgs, enclosingStmt, enclosingCallable, nextIdx, extractVarargAsArray = true )
1904
+ extractCallValueArguments(id, valueArgsWithDummies + extraArgs, callTarget, locId, enclosingStmt, enclosingCallable, nextIdx, extractVarargAsArray = true )
1904
1905
}
1905
1906
1906
1907
private fun getFunctionInvokeMethod (typeArgs : List <IrTypeArgument >): IrFunction ? {
@@ -2022,7 +2023,7 @@ open class KotlinFileExtractor(
2022
2023
childIdx,
2023
2024
enclosingStmt,
2024
2025
valueArguments.size,
2025
- { argParent, idxOffset -> extractCallValueArguments(argParent, valueArguments, enclosingStmt, enclosingCallable, idxOffset) },
2026
+ { argParent, idxOffset -> extractCallValueArguments(argParent, valueArguments, syntacticCallTarget, locId, enclosingStmt, enclosingCallable, idxOffset) },
2026
2027
dispatchReceiver?.type,
2027
2028
dispatchReceiver?.let { { callId -> extractExpressionExpr(dispatchReceiver, enclosingCallable, callId, - 1 , enclosingStmt) } },
2028
2029
extensionReceiver?.let { { argParent -> extractExpressionExpr(extensionReceiver, enclosingCallable, argParent, 0 , enclosingStmt) } },
@@ -2116,19 +2117,38 @@ open class KotlinFileExtractor(
2116
2117
this is IrEnumEntry
2117
2118
2118
2119
2119
- private fun extractCallValueArguments (callId : Label <out DbExprparent >, call : IrFunctionAccessExpression , enclosingStmt : Label <out DbStmt >, enclosingCallable : Label <out DbCallable >, idxOffset : Int ) =
2120
- extractCallValueArguments(callId, (0 until call.valueArgumentsCount).map { call.getValueArgument(it) }, enclosingStmt, enclosingCallable, idxOffset)
2120
+ private fun extractCallValueArguments (callId : Label <out DbExprparent >, call : IrFunctionAccessExpression , callTarget : IrFunction , fallbackLocation : Label < DbLocation >, enclosingStmt : Label <out DbStmt >, enclosingCallable : Label <out DbCallable >, idxOffset : Int ) =
2121
+ extractCallValueArguments(callId, (0 until call.valueArgumentsCount).map { call.getValueArgument(it) }, callTarget, fallbackLocation, enclosingStmt, enclosingCallable, idxOffset)
2121
2122
2122
- private fun extractCallValueArguments (callId : Label <out DbExprparent >, valueArguments : List <IrExpression ?>, enclosingStmt : Label <out DbStmt >, enclosingCallable : Label <out DbCallable >, idxOffset : Int , extractVarargAsArray : Boolean = false) {
2123
+ private fun extractCallValueArguments (callId : Label <out DbExprparent >, valueArguments : List <IrExpression ?>, callTarget : IrFunction , fallbackLocation : Label < DbLocation >, enclosingStmt : Label <out DbStmt >, enclosingCallable : Label <out DbCallable >, idxOffset : Int , extractVarargAsArray : Boolean = false) {
2123
2124
var i = 0
2124
2125
valueArguments.forEach { arg ->
2125
- if (arg != null ) {
2126
+ if (arg != null ) {
2126
2127
if (arg is IrVararg && ! extractVarargAsArray) {
2127
2128
arg.elements.forEachIndexed { varargNo, vararg -> extractVarargElement(vararg, enclosingCallable, callId, i + idxOffset + varargNo, enclosingStmt) }
2128
2129
i + = arg.elements.size
2129
2130
} else {
2130
2131
extractExpressionExpr(arg, enclosingCallable, callId, (i++ ) + idxOffset, enclosingStmt)
2131
2132
}
2133
+ } else {
2134
+ val realCallTarget = callTarget.target.realOverrideTarget
2135
+
2136
+ // Generated constructor calls to kotlin.Enum have no arguments in IR, but the constructor takes two parameters.
2137
+ if (realCallTarget is IrConstructor &&
2138
+ realCallTarget.parentClassOrNull?.symbol == pluginContext.irBuiltIns.enumClass &&
2139
+ realCallTarget.valueParameters.size == 2 &&
2140
+ i < realCallTarget.valueParameters.size) {
2141
+
2142
+ if (i == 0 && realCallTarget.valueParameters[i].type == pluginContext.irBuiltIns.stringType) {
2143
+
2144
+ val id = extractNull(pluginContext.irBuiltIns.stringType, fallbackLocation, callId, (i++ ) + idxOffset, enclosingCallable, enclosingStmt)
2145
+ tw.writeCompiler_generated(id, CompilerGeneratedKinds .ENUM_CONSTRUCTOR_ARGUMENT .kind)
2146
+ } else if (i == 1 && realCallTarget.valueParameters[i].type == pluginContext.irBuiltIns.intType) {
2147
+
2148
+ val id = extractConstantInteger(0 , fallbackLocation, callId, (i++ ) + idxOffset, enclosingCallable, enclosingStmt)
2149
+ tw.writeCompiler_generated(id, CompilerGeneratedKinds .ENUM_CONSTRUCTOR_ARGUMENT .kind)
2150
+ }
2151
+ }
2132
2152
}
2133
2153
}
2134
2154
}
@@ -3067,11 +3087,11 @@ open class KotlinFileExtractor(
3067
3087
// which have null arguments even though the parameters don't give default values.
3068
3088
val id = if (e !is IrEnumConstructorCall && callUsesDefaultArguments(e.symbol.owner, valueArgs)) {
3069
3089
extractNewExpr(getDefaultsMethodLabel(e.symbol.owner).cast(), type, locId, parent, idx, callable, enclosingStmt).also {
3070
- extractDefaultsCallArguments(it, e.symbol.owner, callable, enclosingStmt, valueArgs, null , null )
3090
+ extractDefaultsCallArguments(it, e.symbol.owner, locId, callable, enclosingStmt, valueArgs, null , null )
3071
3091
}
3072
3092
} else {
3073
3093
extractNewExpr(e.symbol.owner, eType.arguments, type, locId, parent, idx, callable, enclosingStmt).also {
3074
- extractCallValueArguments(it, e, enclosingStmt, callable, 0 )
3094
+ extractCallValueArguments(it, e, e.symbol.owner, locId, enclosingStmt, callable, 0 )
3075
3095
}
3076
3096
}
3077
3097
@@ -3396,6 +3416,14 @@ open class KotlinFileExtractor(
3396
3416
extractExprContext(it, locId, callable, enclosingStmt)
3397
3417
}
3398
3418
3419
+ private fun extractNull (t : IrType , locId : Label <DbLocation >, parent : Label <out DbExprparent >, idx : Int , callable : Label <out DbCallable >, enclosingStmt : Label <out DbStmt >) =
3420
+ tw.getFreshIdLabel<DbNullliteral >().also {
3421
+ val type = useType(t)
3422
+ tw.writeExprs_nullliteral(it, type.javaResult.id, parent, idx)
3423
+ tw.writeExprsKotlinType(it, type.kotlinResult.id)
3424
+ extractExprContext(it, locId, callable, enclosingStmt)
3425
+ }
3426
+
3399
3427
private fun extractAssignExpr (type : IrType , locId : Label <DbLocation >, parent : Label <out DbExprparent >, idx : Int , callable : Label <out DbCallable >, enclosingStmt : Label <out DbStmt >) =
3400
3428
tw.getFreshIdLabel<DbAssignexpr >().also {
3401
3429
val typeResults = useType(type)
@@ -3436,7 +3464,7 @@ open class KotlinFileExtractor(
3436
3464
3437
3465
tw.writeHasLocation(id, locId)
3438
3466
tw.writeCallableBinding(id.cast<DbCaller >(), methodId)
3439
- extractCallValueArguments(id, e, id, callable, 0 )
3467
+ extractCallValueArguments(id, e, e.symbol.owner, locId, id, callable, 0 )
3440
3468
val dr = e.dispatchReceiver
3441
3469
if (dr != null ) {
3442
3470
extractExpressionExpr(dr, callable, id, - 1 , id)
@@ -3614,12 +3642,7 @@ open class KotlinFileExtractor(
3614
3642
tw.writeNamestrings(v.toString(), v.toString(), id)
3615
3643
}
3616
3644
v == null -> {
3617
- val id = tw.getFreshIdLabel<DbNullliteral >()
3618
- val type = useType(e.type) // class;kotlin.Nothing
3619
- val locId = tw.getLocation(e)
3620
- tw.writeExprs_nullliteral(id, type.javaResult.id, exprParent.parent, exprParent.idx)
3621
- tw.writeExprsKotlinType(id, type.kotlinResult.id)
3622
- extractExprContext(id, locId, callable, exprParent.enclosingStmt)
3645
+ extractNull(e.type, tw.getLocation(e), exprParent.parent, exprParent.idx, callable, exprParent.enclosingStmt)
3623
3646
}
3624
3647
else -> {
3625
3648
logger.errorElement(" Unrecognised IrConst: " + v.javaClass, e)
@@ -5516,5 +5539,6 @@ open class KotlinFileExtractor(
5516
5539
JVMOVERLOADS_METHOD (9 ),
5517
5540
DEFAULT_ARGUMENTS_METHOD (10 ),
5518
5541
INTERFACE_FORWARDER (11 ),
5542
+ ENUM_CONSTRUCTOR_ARGUMENT (12 ),
5519
5543
}
5520
5544
}
0 commit comments