@@ -552,9 +552,13 @@ open class KotlinFileExtractor(
552
552
logger.warnElement(" Expected annotation property to define a getter" , prop)
553
553
} else {
554
554
val getterId = useFunction<DbMethod >(getter)
555
- val exprId = extractAnnotationValueExpression(v, id, i, " {$getterId }" , getter.returnType, extractEnumTypeAccesses)
556
- if (exprId != null ) {
557
- tw.writeAnnotValue(id, getterId, exprId)
555
+ if (getterId == null ) {
556
+ logger.errorElement(" Couldn't get ID for getter" , getter)
557
+ } else {
558
+ val exprId = extractAnnotationValueExpression(v, id, i, " {$getterId }" , getter.returnType, extractEnumTypeAccesses)
559
+ if (exprId != null ) {
560
+ tw.writeAnnotValue(id, getterId, exprId)
561
+ }
558
562
}
559
563
}
560
564
}
@@ -979,6 +983,10 @@ open class KotlinFileExtractor(
979
983
private fun extractInstanceInitializerBlock (parent : StmtParent , enclosingConstructor : IrConstructor ) {
980
984
with (" object initializer block" , enclosingConstructor) {
981
985
val constructorId = useFunction<DbConstructor >(enclosingConstructor)
986
+ if (constructorId == null ) {
987
+ logger.errorElement(" Cannot get ID for constructor" , enclosingConstructor)
988
+ return
989
+ }
982
990
val enclosingClass = enclosingConstructor.parentClassOrNull
983
991
if (enclosingClass == null ) {
984
992
logger.errorElement(" Constructor's parent is not a class" , enclosingConstructor)
@@ -1410,10 +1418,17 @@ open class KotlinFileExtractor(
1410
1418
1411
1419
val sourceDeclaration =
1412
1420
overriddenAttributes?.sourceDeclarationId ? :
1413
- if (typeSubstitution != null && overriddenAttributes?.id == null )
1414
- useFunction(f)
1415
- else
1421
+ if (typeSubstitution != null && overriddenAttributes?.id == null ) {
1422
+ val sourceFunId = useFunction<DbCallable >(f)
1423
+ if (sourceFunId == null ) {
1424
+ logger.errorElement(" Cannot get source ID for function" , f)
1425
+ id // TODO: This is wrong; we ought to just fail in this case
1426
+ } else {
1427
+ sourceFunId
1428
+ }
1429
+ } else {
1416
1430
id
1431
+ }
1417
1432
1418
1433
val extReceiver = f.extensionReceiverParameter
1419
1434
// The following parameter order is correct, because member $default methods (where the order would be [dispatchParam], [extensionParam], normalParams) are not extracted here
@@ -2926,7 +2941,11 @@ open class KotlinFileExtractor(
2926
2941
tw.writeStmts_throwstmt(throwId, stmtParent.parent, stmtParent.idx, callable)
2927
2942
tw.writeHasLocation(throwId, locId)
2928
2943
val newExprId = extractNewExpr(it, null , thrownType, locId, throwId, 0 , callable, throwId)
2929
- extractTypeAccess(thrownType, locId, newExprId, - 3 , callable, throwId)
2944
+ if (newExprId == null ) {
2945
+ logger.errorElement(" No ID for newExpr in noWhenBranchMatchedException" , c)
2946
+ } else {
2947
+ extractTypeAccess(thrownType, locId, newExprId, - 3 , callable, throwId)
2948
+ }
2930
2949
}
2931
2950
}
2932
2951
isBuiltinCallInternal(c, " illegalArgumentException" ) -> {
@@ -3270,7 +3289,14 @@ open class KotlinFileExtractor(
3270
3289
idx : Int ,
3271
3290
callable : Label <out DbCallable >,
3272
3291
enclosingStmt : Label <out DbStmt >
3273
- ): Label <DbNewexpr > = extractNewExpr(useFunction<DbConstructor >(calledConstructor, constructorTypeArgs), constructedType, locId, parent, idx, callable, enclosingStmt)
3292
+ ): Label <DbNewexpr >? {
3293
+ val funId = useFunction<DbConstructor >(calledConstructor, constructorTypeArgs)
3294
+ if (funId == null ) {
3295
+ logger.error(" Cannot get ID for newExpr function" )
3296
+ return null
3297
+ }
3298
+ return extractNewExpr(funId, constructedType, locId, parent, idx, callable, enclosingStmt)
3299
+ }
3274
3300
3275
3301
private fun needsObinitFunction (c : IrClass ) = c.primaryConstructor == null && c.constructors.count() > 1
3276
3302
@@ -3310,26 +3336,31 @@ open class KotlinFileExtractor(
3310
3336
extractDefaultsCallArguments(it, e.symbol.owner, callable, enclosingStmt, valueArgs, null , null )
3311
3337
}
3312
3338
} 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
- }
3339
+ val newExprId = extractNewExpr(e.symbol.owner, eType.arguments, type, locId, parent, idx, callable, enclosingStmt)
3340
+ if (newExprId == null ) {
3341
+ logger.errorElement(" Cannot get newExpr ID" , e)
3342
+ return
3343
+ }
3344
+
3345
+ val realCallTarget = e.symbol.owner.realOverrideTarget
3346
+ // Generated constructor calls to kotlin.Enum have no arguments in IR, but the constructor takes two parameters.
3347
+ if (e is IrEnumConstructorCall &&
3348
+ realCallTarget is IrConstructor &&
3349
+ realCallTarget.parentClassOrNull?.fqNameWhenAvailable?.asString() == " kotlin.Enum" &&
3350
+ realCallTarget.valueParameters.size == 2 &&
3351
+ realCallTarget.valueParameters[0 ].type == pluginContext.irBuiltIns.stringType &&
3352
+ realCallTarget.valueParameters[1 ].type == pluginContext.irBuiltIns.intType) {
3353
+
3354
+ val id0 = extractNull(pluginContext.irBuiltIns.stringType, locId, newExprId, 0 , callable, enclosingStmt)
3355
+ tw.writeCompiler_generated(id0, CompilerGeneratedKinds .ENUM_CONSTRUCTOR_ARGUMENT .kind)
3356
+
3357
+ val id1 = extractConstantInteger(0 , locId, newExprId, 1 , callable, enclosingStmt)
3358
+ tw.writeCompiler_generated(id1, CompilerGeneratedKinds .ENUM_CONSTRUCTOR_ARGUMENT .kind)
3359
+ } else {
3360
+ extractCallValueArguments(newExprId, e, enclosingStmt, callable, 0 )
3332
3361
}
3362
+
3363
+ newExprId
3333
3364
}
3334
3365
3335
3366
if (isAnonymous) {
@@ -3698,9 +3729,13 @@ open class KotlinFileExtractor(
3698
3729
3699
3730
val locId = tw.getLocation(e)
3700
3731
val methodId = useFunction<DbConstructor >(e.symbol.owner)
3732
+ if (methodId == null ) {
3733
+ logger.errorElement(" Cannot get ID for delegating constructor" , e)
3734
+ } else {
3735
+ tw.writeCallableBinding(id.cast<DbCaller >(), methodId)
3736
+ }
3701
3737
3702
3738
tw.writeHasLocation(id, locId)
3703
- tw.writeCallableBinding(id.cast<DbCaller >(), methodId)
3704
3739
extractCallValueArguments(id, e, id, callable, 0 )
3705
3740
val dr = e.dispatchReceiver
3706
3741
if (dr != null ) {
@@ -4636,7 +4671,11 @@ open class KotlinFileExtractor(
4636
4671
extractExprContext(callId, locId, labels.methodId, retId)
4637
4672
4638
4673
val callableId = useFunction<DbCallable >(target.owner.realOverrideTarget, classTypeArgsIncludingOuterClasses)
4639
- tw.writeCallableBinding(callId.cast<DbCaller >(), callableId)
4674
+ if (callableId == null ) {
4675
+ logger.error(" Cannot get ID for reflection target" )
4676
+ } else {
4677
+ tw.writeCallableBinding(callId.cast<DbCaller >(), callableId)
4678
+ }
4640
4679
4641
4680
val useFirstArgAsDispatch: Boolean
4642
4681
if (dispatchReceiverInfo != null ) {
@@ -4818,20 +4857,24 @@ open class KotlinFileExtractor(
4818
4857
val getterReturnType = parameterTypes.last()
4819
4858
4820
4859
if (getter != null ) {
4821
- val getLabels = addFunctionManual(tw.getFreshIdLabel(), OperatorNameConventions .GET .asString(), getterParameterTypes, getterReturnType, classId, locId)
4822
4860
val getterCallableId = useFunction<DbCallable >(getter.owner.realOverrideTarget, classTypeArguments)
4861
+ if (getterCallableId == null ) {
4862
+ logger.errorElement(" Cannot get ID for getter" , propertyReferenceExpr)
4863
+ } else {
4864
+ val getLabels = addFunctionManual(tw.getFreshIdLabel(), OperatorNameConventions .GET .asString(), getterParameterTypes, getterReturnType, classId, locId)
4865
+
4866
+ helper.extractCallToReflectionTarget(
4867
+ getLabels,
4868
+ getter,
4869
+ getterReturnType,
4870
+ expressionTypeArguments,
4871
+ classTypeArguments
4872
+ )
4823
4873
4824
- helper.extractCallToReflectionTarget(
4825
- getLabels,
4826
- getter,
4827
- getterReturnType,
4828
- expressionTypeArguments,
4829
- classTypeArguments
4830
- )
4831
-
4832
- tw.writePropertyRefGetBinding(idPropertyRef, getterCallableId)
4874
+ tw.writePropertyRefGetBinding(idPropertyRef, getterCallableId)
4833
4875
4834
- helper.extractPropertyReferenceInvoke(getLabels.methodId, getterParameterTypes, getterReturnType)
4876
+ helper.extractPropertyReferenceInvoke(getLabels.methodId, getterParameterTypes, getterReturnType)
4877
+ }
4835
4878
} else {
4836
4879
// Property without a getter.
4837
4880
if (backingField == null ) {
@@ -4852,19 +4895,22 @@ open class KotlinFileExtractor(
4852
4895
}
4853
4896
4854
4897
if (setter != null ) {
4855
- val setLabels = addFunctionManual(tw.getFreshIdLabel(), OperatorNameConventions .SET .asString(), parameterTypes, pluginContext.irBuiltIns.unitType, classId, locId)
4856
-
4857
4898
val setterCallableId = useFunction<DbCallable >(setter.owner.realOverrideTarget, classTypeArguments)
4899
+ if (setterCallableId == null ) {
4900
+ logger.errorElement(" Cannot get ID for setter" , propertyReferenceExpr)
4901
+ } else {
4902
+ val setLabels = addFunctionManual(tw.getFreshIdLabel(), OperatorNameConventions .SET .asString(), parameterTypes, pluginContext.irBuiltIns.unitType, classId, locId)
4858
4903
4859
- helper.extractCallToReflectionTarget(
4860
- setLabels,
4861
- setter,
4862
- pluginContext.irBuiltIns.unitType,
4863
- expressionTypeArguments,
4864
- classTypeArguments
4865
- )
4904
+ helper.extractCallToReflectionTarget(
4905
+ setLabels,
4906
+ setter,
4907
+ pluginContext.irBuiltIns.unitType,
4908
+ expressionTypeArguments,
4909
+ classTypeArguments
4910
+ )
4866
4911
4867
- tw.writePropertyRefSetBinding(idPropertyRef, setterCallableId)
4912
+ tw.writePropertyRefSetBinding(idPropertyRef, setterCallableId)
4913
+ }
4868
4914
} else {
4869
4915
if (backingField != null && ! backingField.owner.isFinal) {
4870
4916
val setLabels = addFunctionManual(tw.getFreshIdLabel(), OperatorNameConventions .SET .asString(), parameterTypes, pluginContext.irBuiltIns.unitType, classId, locId)
@@ -4999,7 +5045,11 @@ open class KotlinFileExtractor(
4999
5045
tw.writeCallableBinding(idMemberRef, ids.constructor )
5000
5046
5001
5047
val targetCallableId = useFunction<DbCallable >(target.owner.realOverrideTarget, classTypeArguments)
5002
- tw.writeMemberRefBinding(idMemberRef, targetCallableId)
5048
+ if (targetCallableId == null ) {
5049
+ logger.errorElement(" Cannot get ID for function reference callable" , functionReferenceExpr)
5050
+ } else {
5051
+ tw.writeMemberRefBinding(idMemberRef, targetCallableId)
5052
+ }
5003
5053
5004
5054
val helper = CallableReferenceHelper (functionReferenceExpr, locId, ids)
5005
5055
@@ -5145,7 +5195,11 @@ open class KotlinFileExtractor(
5145
5195
tw.writeExprsKotlinType(callId, callType.kotlinResult.id)
5146
5196
extractExprContext(callId, locId, funLabels.methodId, retId)
5147
5197
val calledMethodId = useFunction<DbMethod >(lambda)
5148
- tw.writeCallableBinding(callId, calledMethodId)
5198
+ if (calledMethodId == null ) {
5199
+ logger.errorElement(" Cannot get ID for called lambda" , lambda)
5200
+ } else {
5201
+ tw.writeCallableBinding(callId, calledMethodId)
5202
+ }
5149
5203
5150
5204
// this access
5151
5205
extractThisAccess(ids.type, funLabels.methodId, callId, - 1 , retId, locId)
@@ -5614,7 +5668,11 @@ open class KotlinFileExtractor(
5614
5668
tw.writeExprsKotlinType(callId, callType.kotlinResult.id)
5615
5669
extractExprContext(callId, locId, ids.function, returnId)
5616
5670
val calledMethodId = useFunction<DbMethod >(invokeMethod, functionType.arguments)
5617
- tw.writeCallableBinding(callId, calledMethodId)
5671
+ if (calledMethodId == null ) {
5672
+ logger.errorElement(" Cannot get ID for called method" , invokeMethod)
5673
+ } else {
5674
+ tw.writeCallableBinding(callId, calledMethodId)
5675
+ }
5618
5676
5619
5677
// <fn> access
5620
5678
val lhsId = tw.getFreshIdLabel<DbVaraccess >()
@@ -5737,14 +5795,17 @@ open class KotlinFileExtractor(
5737
5795
if (baseConstructor == null ) {
5738
5796
logger.warnElement(" Cannot find base constructor" , elementToReportOn)
5739
5797
} else {
5740
- val superCallId = tw.getFreshIdLabel<DbSuperconstructorinvocationstmt >()
5741
- tw.writeStmts_superconstructorinvocationstmt(superCallId, constructorBlockId, 0 , ids.constructor )
5742
-
5743
5798
val baseConstructorId = useFunction<DbConstructor >(baseConstructor)
5799
+ if (baseConstructorId == null ) {
5800
+ logger.errorElement(" Cannot find base constructor ID" , elementToReportOn)
5801
+ } else {
5802
+ val superCallId = tw.getFreshIdLabel<DbSuperconstructorinvocationstmt >()
5803
+ tw.writeStmts_superconstructorinvocationstmt(superCallId, constructorBlockId, 0 , ids.constructor )
5744
5804
5745
- tw.writeHasLocation(superCallId, locId)
5746
- tw.writeCallableBinding(superCallId.cast<DbCaller >(), baseConstructorId)
5747
- extractSuperconstructorArgs(superCallId)
5805
+ tw.writeHasLocation(superCallId, locId)
5806
+ tw.writeCallableBinding(superCallId.cast<DbCaller >(), baseConstructorId)
5807
+ extractSuperconstructorArgs(superCallId)
5808
+ }
5748
5809
}
5749
5810
}
5750
5811
0 commit comments