@@ -472,7 +472,7 @@ open class KotlinFileExtractor(
472472
473473 private fun extractObinitFunction (c : IrClass , parentId : Label <out DbClassorinterface >) {
474474 // add method:
475- val obinitLabel = getObinitLabel(c)
475+ val obinitLabel = getObinitLabel(c, parentId )
476476 val obinitId = tw.getLabelFor<DbMethod >(obinitLabel)
477477 val returnType = useType(pluginContext.irBuiltIns.unitType, TypeContext .RETURN )
478478 tw.writeMethods(obinitId, " <obinit>" , " <obinit>()" , returnType.javaResult.id, parentId, obinitId)
@@ -1160,6 +1160,10 @@ open class KotlinFileExtractor(
11601160 return
11611161
11621162 val id = getDefaultsMethodLabel(f)
1163+ if (id == null ) {
1164+ logger.errorElement(" Cannot get defaults method label for function" , f)
1165+ return
1166+ }
11631167 val locId = getLocation(f, null )
11641168 val extReceiver = f.extensionReceiverParameter
11651169 val dispatchReceiver = if (f.shouldExtractAsStatic) null else f.dispatchReceiverParameter
@@ -1284,6 +1288,10 @@ open class KotlinFileExtractor(
12841288 useDeclarationParent(f.parent, false )
12851289 else
12861290 parentId
1291+ if (sourceParentId == null ) {
1292+ logger.errorElement(" Cannot get source parent ID for function" , f)
1293+ return
1294+ }
12871295 val sourceDeclId = tw.getLabelFor<DbCallable >(getFunctionLabel(f, sourceParentId, listOf (), overloadParameters))
12881296 val overriddenAttributes = OverriddenFunctionAttributes (id = overloadId, sourceDeclarationId = sourceDeclId, valueParameters = overloadParameters)
12891297 forceExtractFunction(f, parentId, extractBody = false , extractMethodAndParameterTypeAccesses, extractAnnotations = false , typeSubstitution, classTypeArgsIncludingOuterClasses, overriddenAttributes = overriddenAttributes)
@@ -1301,7 +1309,7 @@ open class KotlinFileExtractor(
13011309 val constructorCallId = tw.getFreshIdLabel<DbConstructorinvocationstmt >()
13021310 tw.writeStmts_constructorinvocationstmt(constructorCallId, blockId, 0 , overloadId)
13031311 tw.writeHasLocation(constructorCallId, realFunctionLocId)
1304- tw.writeCallableBinding(constructorCallId, getDefaultsMethodLabel(f))
1312+ tw.writeCallableBinding(constructorCallId, getDefaultsMethodLabel(f, parentId ))
13051313
13061314 extractDefaultsCallArguments(constructorCallId, f, overloadId, constructorCallId, regularArgs, null , null )
13071315 } else {
@@ -2081,13 +2089,23 @@ open class KotlinFileExtractor(
20812089 getFunctionShortName(f).nameInDB + " \$ default"
20822090 }
20832091
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 > {
20852103 val defaultsMethodName = if (f is IrConstructor ) " <init>" else getDefaultsMethodName(f)
20862104 val argTypes = getDefaultsMethodArgTypes(f)
20872105
20882106 val defaultMethodLabelStr = getFunctionLabel(
20892107 f.parent,
2090- maybeParentId = null ,
2108+ parentId ,
20912109 defaultsMethodName,
20922110 argTypes,
20932111 erase(f.returnType),
@@ -3300,9 +3318,9 @@ open class KotlinFileExtractor(
33003318
33013319 private fun needsObinitFunction (c : IrClass ) = c.primaryConstructor == null && c.constructors.count() > 1
33023320
3303- private fun getObinitLabel (c : IrClass ) = getFunctionLabel(
3321+ private fun getObinitLabel (c : IrClass , parentId : Label < out DbElement >): String = getFunctionLabel(
33043322 c,
3305- null ,
3323+ parentId ,
33063324 " <obinit>" ,
33073325 listOf (),
33083326 pluginContext.irBuiltIns.unitType,
@@ -3332,7 +3350,12 @@ open class KotlinFileExtractor(
33323350 val valueArgs = (0 until e.valueArgumentsCount).map { e.getValueArgument(it) }
33333351
33343352 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 {
33363359 extractDefaultsCallArguments(it, e.symbol.owner, callable, enclosingStmt, valueArgs, null , null )
33373360 }
33383361 } else {
@@ -3817,7 +3840,13 @@ open class KotlinFileExtractor(
38173840 val id = tw.getFreshIdLabel<DbMethodaccess >()
38183841 val type = useType(pluginContext.irBuiltIns.unitType)
38193842 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)
38213850 val methodId = tw.getLabelFor<DbMethod >(methodLabel)
38223851 tw.writeExprs_methodaccess(id, type.javaResult.id, exprParent.parent, exprParent.idx)
38233852 tw.writeExprsKotlinType(id, type.kotlinResult.id)
0 commit comments