@@ -2089,7 +2089,7 @@ open class KotlinFileExtractor(
20892089 private fun extractCallValueArguments (callId : Label <out DbExprparent >, valueArguments : List <IrExpression ?>, enclosingStmt : Label <out DbStmt >, enclosingCallable : Label <out DbCallable >, idxOffset : Int , extractVarargAsArray : Boolean = false) {
20902090 var i = 0
20912091 valueArguments.forEach { arg ->
2092- if (arg != null ) {
2092+ if (arg != null ) {
20932093 if (arg is IrVararg && ! extractVarargAsArray) {
20942094 arg.elements.forEachIndexed { varargNo, vararg -> extractVarargElement(vararg, enclosingCallable, callId, i + idxOffset + varargNo, enclosingStmt) }
20952095 i + = arg.elements.size
@@ -3030,15 +3030,31 @@ open class KotlinFileExtractor(
30303030 val isAnonymous = eType.isAnonymous
30313031 val locId = tw.getLocation(e)
30323032 val valueArgs = (0 until e.valueArgumentsCount).map { e.getValueArgument(it) }
3033- // For now, don't try to use default methods for enum constructor calls,
3034- // which have null arguments even though the parameters don't give default values.
3033+
30353034 val id = if (e !is IrEnumConstructorCall && callUsesDefaultArguments(e.symbol.owner, valueArgs)) {
30363035 extractNewExpr(getDefaultsMethodLabel(e.symbol.owner).cast(), type, locId, parent, idx, callable, enclosingStmt).also {
30373036 extractDefaultsCallArguments(it, e.symbol.owner, callable, enclosingStmt, valueArgs, null , null )
30383037 }
30393038 } else {
30403039 extractNewExpr(e.symbol.owner, eType.arguments, type, locId, parent, idx, callable, enclosingStmt).also {
3041- extractCallValueArguments(it, e, enclosingStmt, callable, 0 )
3040+
3041+ val realCallTarget = e.symbol.owner.realOverrideTarget
3042+ // Generated constructor calls to kotlin.Enum have no arguments in IR, but the constructor takes two parameters.
3043+ if (e is IrEnumConstructorCall &&
3044+ realCallTarget is IrConstructor &&
3045+ realCallTarget.parentClassOrNull?.fqNameWhenAvailable?.asString() == " kotlin.Enum" &&
3046+ realCallTarget.valueParameters.size == 2 &&
3047+ realCallTarget.valueParameters[0 ].type == pluginContext.irBuiltIns.stringType &&
3048+ realCallTarget.valueParameters[1 ].type == pluginContext.irBuiltIns.intType) {
3049+
3050+ val id0 = extractNull(pluginContext.irBuiltIns.stringType, locId, it, 0 , callable, enclosingStmt)
3051+ tw.writeCompiler_generated(id0, CompilerGeneratedKinds .ENUM_CONSTRUCTOR_ARGUMENT .kind)
3052+
3053+ val id1 = extractConstantInteger(0 , locId, it, 1 , callable, enclosingStmt)
3054+ tw.writeCompiler_generated(id1, CompilerGeneratedKinds .ENUM_CONSTRUCTOR_ARGUMENT .kind)
3055+ } else {
3056+ extractCallValueArguments(it, e, enclosingStmt, callable, 0 )
3057+ }
30423058 }
30433059 }
30443060
@@ -3363,6 +3379,14 @@ open class KotlinFileExtractor(
33633379 extractExprContext(it, locId, callable, enclosingStmt)
33643380 }
33653381
3382+ private fun extractNull (t : IrType , locId : Label <DbLocation >, parent : Label <out DbExprparent >, idx : Int , callable : Label <out DbCallable >, enclosingStmt : Label <out DbStmt >) =
3383+ tw.getFreshIdLabel<DbNullliteral >().also {
3384+ val type = useType(t)
3385+ tw.writeExprs_nullliteral(it, type.javaResult.id, parent, idx)
3386+ tw.writeExprsKotlinType(it, type.kotlinResult.id)
3387+ extractExprContext(it, locId, callable, enclosingStmt)
3388+ }
3389+
33663390 private fun extractAssignExpr (type : IrType , locId : Label <DbLocation >, parent : Label <out DbExprparent >, idx : Int , callable : Label <out DbCallable >, enclosingStmt : Label <out DbStmt >) =
33673391 tw.getFreshIdLabel<DbAssignexpr >().also {
33683392 val typeResults = useType(type)
@@ -3581,12 +3605,7 @@ open class KotlinFileExtractor(
35813605 tw.writeNamestrings(v.toString(), v.toString(), id)
35823606 }
35833607 v == null -> {
3584- val id = tw.getFreshIdLabel<DbNullliteral >()
3585- val type = useType(e.type) // class;kotlin.Nothing
3586- val locId = tw.getLocation(e)
3587- tw.writeExprs_nullliteral(id, type.javaResult.id, exprParent.parent, exprParent.idx)
3588- tw.writeExprsKotlinType(id, type.kotlinResult.id)
3589- extractExprContext(id, locId, callable, exprParent.enclosingStmt)
3608+ extractNull(e.type, tw.getLocation(e), exprParent.parent, exprParent.idx, callable, exprParent.enclosingStmt)
35903609 }
35913610 else -> {
35923611 logger.errorElement(" Unrecognised IrConst: " + v.javaClass, e)
@@ -5483,5 +5502,6 @@ open class KotlinFileExtractor(
54835502 JVMOVERLOADS_METHOD (9 ),
54845503 DEFAULT_ARGUMENTS_METHOD (10 ),
54855504 INTERFACE_FORWARDER (11 ),
5505+ ENUM_CONSTRUCTOR_ARGUMENT (12 ),
54865506 }
54875507}
0 commit comments