@@ -472,7 +472,7 @@ open class KotlinFileExtractor(
472
472
473
473
private fun extractObinitFunction (c : IrClass , parentId : Label <out DbClassorinterface >) {
474
474
// add method:
475
- val obinitLabel = getObinitLabel(c)
475
+ val obinitLabel = getObinitLabel(c, parentId )
476
476
val obinitId = tw.getLabelFor<DbMethod >(obinitLabel)
477
477
val returnType = useType(pluginContext.irBuiltIns.unitType, TypeContext .RETURN )
478
478
tw.writeMethods(obinitId, " <obinit>" , " <obinit>()" , returnType.javaResult.id, parentId, obinitId)
@@ -1160,6 +1160,10 @@ open class KotlinFileExtractor(
1160
1160
return
1161
1161
1162
1162
val id = getDefaultsMethodLabel(f)
1163
+ if (id == null ) {
1164
+ logger.errorElement(" Cannot get defaults method label for function" , f)
1165
+ return
1166
+ }
1163
1167
val locId = getLocation(f, null )
1164
1168
val extReceiver = f.extensionReceiverParameter
1165
1169
val dispatchReceiver = if (f.shouldExtractAsStatic) null else f.dispatchReceiverParameter
@@ -1284,6 +1288,10 @@ open class KotlinFileExtractor(
1284
1288
useDeclarationParent(f.parent, false )
1285
1289
else
1286
1290
parentId
1291
+ if (sourceParentId == null ) {
1292
+ logger.errorElement(" Cannot get source parent ID for function" , f)
1293
+ return
1294
+ }
1287
1295
val sourceDeclId = tw.getLabelFor<DbCallable >(getFunctionLabel(f, sourceParentId, listOf (), overloadParameters))
1288
1296
val overriddenAttributes = OverriddenFunctionAttributes (id = overloadId, sourceDeclarationId = sourceDeclId, valueParameters = overloadParameters)
1289
1297
forceExtractFunction(f, parentId, extractBody = false , extractMethodAndParameterTypeAccesses, extractAnnotations = false , typeSubstitution, classTypeArgsIncludingOuterClasses, overriddenAttributes = overriddenAttributes)
@@ -1301,7 +1309,7 @@ open class KotlinFileExtractor(
1301
1309
val constructorCallId = tw.getFreshIdLabel<DbConstructorinvocationstmt >()
1302
1310
tw.writeStmts_constructorinvocationstmt(constructorCallId, blockId, 0 , overloadId)
1303
1311
tw.writeHasLocation(constructorCallId, realFunctionLocId)
1304
- tw.writeCallableBinding(constructorCallId, getDefaultsMethodLabel(f))
1312
+ tw.writeCallableBinding(constructorCallId, getDefaultsMethodLabel(f, parentId ))
1305
1313
1306
1314
extractDefaultsCallArguments(constructorCallId, f, overloadId, constructorCallId, regularArgs, null , null )
1307
1315
} else {
@@ -2081,13 +2089,23 @@ open class KotlinFileExtractor(
2081
2089
getFunctionShortName(f).nameInDB + " \$ default"
2082
2090
}
2083
2091
2084
- private fun getDefaultsMethodLabel (f : IrFunction ): Label <out DbCallable > {
2092
+ private fun getDefaultsMethodLabel (f : IrFunction ): Label <out DbCallable >? {
2093
+ val classTypeArgsIncludingOuterClasses = null
2094
+ val parentId = useDeclarationParent(f.parent, false , classTypeArgsIncludingOuterClasses, true )
2095
+ if (parentId == null ) {
2096
+ logger.errorElement(" Couldn't get parent ID for defaults method" , f)
2097
+ return null
2098
+ }
2099
+ return getDefaultsMethodLabel(f, parentId)
2100
+ }
2101
+
2102
+ private fun getDefaultsMethodLabel (f : IrFunction , parentId : Label <out DbElement >): Label <out DbCallable > {
2085
2103
val defaultsMethodName = if (f is IrConstructor ) " <init>" else getDefaultsMethodName(f)
2086
2104
val argTypes = getDefaultsMethodArgTypes(f)
2087
2105
2088
2106
val defaultMethodLabelStr = getFunctionLabel(
2089
2107
f.parent,
2090
- maybeParentId = null ,
2108
+ parentId ,
2091
2109
defaultsMethodName,
2092
2110
argTypes,
2093
2111
erase(f.returnType),
@@ -3300,9 +3318,9 @@ open class KotlinFileExtractor(
3300
3318
3301
3319
private fun needsObinitFunction (c : IrClass ) = c.primaryConstructor == null && c.constructors.count() > 1
3302
3320
3303
- private fun getObinitLabel (c : IrClass ) = getFunctionLabel(
3321
+ private fun getObinitLabel (c : IrClass , parentId : Label < out DbElement >): String = getFunctionLabel(
3304
3322
c,
3305
- null ,
3323
+ parentId ,
3306
3324
" <obinit>" ,
3307
3325
listOf (),
3308
3326
pluginContext.irBuiltIns.unitType,
@@ -3332,7 +3350,12 @@ open class KotlinFileExtractor(
3332
3350
val valueArgs = (0 until e.valueArgumentsCount).map { e.getValueArgument(it) }
3333
3351
3334
3352
val id = if (e !is IrEnumConstructorCall && callUsesDefaultArguments(e.symbol.owner, valueArgs)) {
3335
- extractNewExpr(getDefaultsMethodLabel(e.symbol.owner).cast(), type, locId, parent, idx, callable, enclosingStmt).also {
3353
+ val defaultsMethodId = getDefaultsMethodLabel(e.symbol.owner)
3354
+ if (defaultsMethodId == null ) {
3355
+ logger.errorElement(" Cannot get defaults method ID" , e)
3356
+ return
3357
+ }
3358
+ extractNewExpr(defaultsMethodId.cast(), type, locId, parent, idx, callable, enclosingStmt).also {
3336
3359
extractDefaultsCallArguments(it, e.symbol.owner, callable, enclosingStmt, valueArgs, null , null )
3337
3360
}
3338
3361
} else {
@@ -3817,7 +3840,13 @@ open class KotlinFileExtractor(
3817
3840
val id = tw.getFreshIdLabel<DbMethodaccess >()
3818
3841
val type = useType(pluginContext.irBuiltIns.unitType)
3819
3842
val locId = tw.getLocation(e)
3820
- val methodLabel = getObinitLabel(irConstructor.parentAsClass)
3843
+ val parentClass = irConstructor.parentAsClass
3844
+ val parentId = useDeclarationParent(parentClass, false , null , true )
3845
+ if (parentId == null ) {
3846
+ logger.errorElement(" Cannot get parent ID for obinit" , e)
3847
+ return
3848
+ }
3849
+ val methodLabel = getObinitLabel(parentClass, parentId)
3821
3850
val methodId = tw.getLabelFor<DbMethod >(methodLabel)
3822
3851
tw.writeExprs_methodaccess(id, type.javaResult.id, exprParent.parent, exprParent.idx)
3823
3852
tw.writeExprsKotlinType(id, type.kotlinResult.id)
0 commit comments