Skip to content

Commit 3e86c4c

Browse files
committed
Kotlin: Allow extractNewExpr to return null
1 parent 467231e commit 3e86c4c

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,7 +2926,11 @@ open class KotlinFileExtractor(
29262926
tw.writeStmts_throwstmt(throwId, stmtParent.parent, stmtParent.idx, callable)
29272927
tw.writeHasLocation(throwId, locId)
29282928
val newExprId = extractNewExpr(it, null, thrownType, locId, throwId, 0, callable, throwId)
2929-
extractTypeAccess(thrownType, locId, newExprId, -3, callable, throwId)
2929+
if (newExprId == null) {
2930+
logger.errorElement("No ID for newExpr in noWhenBranchMatchedException", c)
2931+
} else {
2932+
extractTypeAccess(thrownType, locId, newExprId, -3, callable, throwId)
2933+
}
29302934
}
29312935
}
29322936
isBuiltinCallInternal(c, "illegalArgumentException") -> {
@@ -3270,7 +3274,7 @@ open class KotlinFileExtractor(
32703274
idx: Int,
32713275
callable: Label<out DbCallable>,
32723276
enclosingStmt: Label<out DbStmt>
3273-
): Label<DbNewexpr> = extractNewExpr(useFunction<DbConstructor>(calledConstructor, constructorTypeArgs), constructedType, locId, parent, idx, callable, enclosingStmt)
3277+
): Label<DbNewexpr>? = extractNewExpr(useFunction<DbConstructor>(calledConstructor, constructorTypeArgs), constructedType, locId, parent, idx, callable, enclosingStmt)
32743278

32753279
private fun needsObinitFunction(c: IrClass) = c.primaryConstructor == null && c.constructors.count() > 1
32763280

@@ -3310,26 +3314,31 @@ open class KotlinFileExtractor(
33103314
extractDefaultsCallArguments(it, e.symbol.owner, callable, enclosingStmt, valueArgs, null, null)
33113315
}
33123316
} else {
3313-
extractNewExpr(e.symbol.owner, eType.arguments, type, locId, parent, idx, callable, enclosingStmt).also {
3314-
3315-
val realCallTarget = e.symbol.owner.realOverrideTarget
3316-
// Generated constructor calls to kotlin.Enum have no arguments in IR, but the constructor takes two parameters.
3317-
if (e is IrEnumConstructorCall &&
3318-
realCallTarget is IrConstructor &&
3319-
realCallTarget.parentClassOrNull?.fqNameWhenAvailable?.asString() == "kotlin.Enum" &&
3320-
realCallTarget.valueParameters.size == 2 &&
3321-
realCallTarget.valueParameters[0].type == pluginContext.irBuiltIns.stringType &&
3322-
realCallTarget.valueParameters[1].type == pluginContext.irBuiltIns.intType) {
3323-
3324-
val id0 = extractNull(pluginContext.irBuiltIns.stringType, locId, it, 0, callable, enclosingStmt)
3325-
tw.writeCompiler_generated(id0, CompilerGeneratedKinds.ENUM_CONSTRUCTOR_ARGUMENT.kind)
3326-
3327-
val id1 = extractConstantInteger(0, locId, it, 1, callable, enclosingStmt)
3328-
tw.writeCompiler_generated(id1, CompilerGeneratedKinds.ENUM_CONSTRUCTOR_ARGUMENT.kind)
3329-
} else {
3330-
extractCallValueArguments(it, e, enclosingStmt, callable, 0)
3331-
}
3317+
val newExprId = extractNewExpr(e.symbol.owner, eType.arguments, type, locId, parent, idx, callable, enclosingStmt)
3318+
if (newExprId == null) {
3319+
logger.errorElement("Cannot get newExpr ID", e)
3320+
return
33323321
}
3322+
3323+
val realCallTarget = e.symbol.owner.realOverrideTarget
3324+
// Generated constructor calls to kotlin.Enum have no arguments in IR, but the constructor takes two parameters.
3325+
if (e is IrEnumConstructorCall &&
3326+
realCallTarget is IrConstructor &&
3327+
realCallTarget.parentClassOrNull?.fqNameWhenAvailable?.asString() == "kotlin.Enum" &&
3328+
realCallTarget.valueParameters.size == 2 &&
3329+
realCallTarget.valueParameters[0].type == pluginContext.irBuiltIns.stringType &&
3330+
realCallTarget.valueParameters[1].type == pluginContext.irBuiltIns.intType) {
3331+
3332+
val id0 = extractNull(pluginContext.irBuiltIns.stringType, locId, newExprId, 0, callable, enclosingStmt)
3333+
tw.writeCompiler_generated(id0, CompilerGeneratedKinds.ENUM_CONSTRUCTOR_ARGUMENT.kind)
3334+
3335+
val id1 = extractConstantInteger(0, locId, newExprId, 1, callable, enclosingStmt)
3336+
tw.writeCompiler_generated(id1, CompilerGeneratedKinds.ENUM_CONSTRUCTOR_ARGUMENT.kind)
3337+
} else {
3338+
extractCallValueArguments(newExprId, e, enclosingStmt, callable, 0)
3339+
}
3340+
3341+
newExprId
33333342
}
33343343

33353344
if (isAnonymous) {

0 commit comments

Comments
 (0)