@@ -1478,9 +1478,21 @@ open class KotlinFileExtractor(
1478
1478
logger.warn(" Cannot find functional interface type for raw method access" )
1479
1479
null
1480
1480
} else {
1481
- val interfaceType = functionalInterface.classOrNull!! .owner
1482
- val substituted = getJavaEquivalentClass(interfaceType) ? : interfaceType
1483
- findFunction(substituted, OperatorNameConventions .INVOKE .asString())!!
1481
+ val functionalInterfaceClass = functionalInterface.classOrNull
1482
+ if (functionalInterfaceClass == null ) {
1483
+ logger.warn(" Cannot find functional interface class for raw method access" )
1484
+ null
1485
+ } else {
1486
+ val interfaceType = functionalInterfaceClass.owner
1487
+ val substituted = getJavaEquivalentClass(interfaceType) ? : interfaceType
1488
+ val function = findFunction(substituted, OperatorNameConventions .INVOKE .asString())
1489
+ if (function == null ) {
1490
+ logger.warn(" Cannot find invoke function for raw method access" )
1491
+ null
1492
+ } else {
1493
+ function
1494
+ }
1495
+ }
1484
1496
}
1485
1497
} else {
1486
1498
callTarget
@@ -1768,10 +1780,15 @@ open class KotlinFileExtractor(
1768
1780
fun extractMethodAccess (syntacticCallTarget : IrFunction , extractMethodTypeArguments : Boolean = true, extractClassTypeArguments : Boolean = false) {
1769
1781
val typeArgs =
1770
1782
if (extractMethodTypeArguments)
1771
- (0 until c.typeArgumentsCount).map { c.getTypeArgument(it)!! }
1783
+ (0 until c.typeArgumentsCount).map { c.getTypeArgument(it) }.requireNoNullsOrNull()
1772
1784
else
1773
1785
listOf ()
1774
1786
1787
+ if (typeArgs == null ) {
1788
+ logger.warn(" Missing type argument in extractMethodAccess" )
1789
+ return
1790
+ }
1791
+
1775
1792
extractRawMethodAccess(syntacticCallTarget, c, callable, parent, idx, enclosingStmt, (0 until c.valueArgumentsCount).map { c.getValueArgument(it) }, c.dispatchReceiver, c.extensionReceiver, typeArgs, extractClassTypeArguments, c.superQualifierSymbol)
1776
1793
}
1777
1794
@@ -2036,7 +2053,12 @@ open class KotlinFileExtractor(
2036
2053
tw.writeCallableEnclosingExpr(id, callable)
2037
2054
2038
2055
if (c.typeArgumentsCount == 1 ) {
2039
- extractTypeAccessRecursive(c.getTypeArgument(0 )!! , locId, id, - 1 , callable, enclosingStmt, TypeContext .GENERIC_ARGUMENT )
2056
+ val typeArgument = c.getTypeArgument(0 )
2057
+ if (typeArgument == null ) {
2058
+ logger.errorElement(" Type argument missing in an arrayOfNulls call" , c)
2059
+ } else {
2060
+ extractTypeAccessRecursive(typeArgument, locId, id, - 1 , callable, enclosingStmt, TypeContext .GENERIC_ARGUMENT )
2061
+ }
2040
2062
} else {
2041
2063
logger.errorElement(" Expected to find exactly one type argument in an arrayOfNulls call" , c)
2042
2064
}
@@ -2099,7 +2121,12 @@ open class KotlinFileExtractor(
2099
2121
2100
2122
if (isBuiltinCallKotlin(c, " arrayOf" )) {
2101
2123
if (c.typeArgumentsCount == 1 ) {
2102
- extractTypeAccessRecursive(c.getTypeArgument(0 )!! , locId, id, - 1 , callable, enclosingStmt, TypeContext .GENERIC_ARGUMENT )
2124
+ val typeArgument = c.getTypeArgument(0 )
2125
+ if (typeArgument == null ) {
2126
+ logger.errorElement(" Type argument missing in an arrayOf call" , c)
2127
+ } else {
2128
+ extractTypeAccessRecursive(typeArgument, locId, id, - 1 , callable, enclosingStmt, TypeContext .GENERIC_ARGUMENT )
2129
+ }
2103
2130
} else {
2104
2131
logger.errorElement(" Expected to find one type argument in arrayOf call" , c )
2105
2132
}
@@ -2152,13 +2179,18 @@ open class KotlinFileExtractor(
2152
2179
}
2153
2180
isFunction(target, " kotlin" , " (some array type)" , { isArrayType(it) }, " iterator" ) && c.origin == IrStatementOrigin .FOR_LOOP_ITERATOR -> {
2154
2181
findTopLevelFunctionOrWarn(" kotlin.jvm.internal.iterator" , " kotlin.jvm.internal.ArrayIteratorKt" , c)?.let { iteratorFn ->
2155
- val typeArgs = (c.dispatchReceiver!! .type as IrSimpleType ).arguments.map {
2156
- when (it) {
2157
- is IrTypeProjection -> it.type
2158
- else -> pluginContext.irBuiltIns.anyNType
2182
+ val dispatchReceiver = c.dispatchReceiver
2183
+ if (dispatchReceiver == null ) {
2184
+ logger.errorElement(" No dispatch receiver found for array iterator call" , c)
2185
+ } else {
2186
+ val typeArgs = (dispatchReceiver.type as IrSimpleType ).arguments.map {
2187
+ when (it) {
2188
+ is IrTypeProjection -> it.type
2189
+ else -> pluginContext.irBuiltIns.anyNType
2190
+ }
2159
2191
}
2192
+ extractRawMethodAccess(iteratorFn, c, callable, parent, idx, enclosingStmt, listOf (c.dispatchReceiver), null , null , typeArgs)
2160
2193
}
2161
- extractRawMethodAccess(iteratorFn, c, callable, parent, idx, enclosingStmt, listOf (c.dispatchReceiver), null , null , typeArgs)
2162
2194
}
2163
2195
}
2164
2196
isFunction(target, " kotlin" , " (some array type)" , { isArrayType(it) }, " get" ) && c.origin == IrStatementOrigin .GET_ARRAY_ELEMENT -> {
@@ -2204,12 +2236,22 @@ open class KotlinFileExtractor(
2204
2236
isBuiltinCall(c, " <unsafe-coerce>" , " kotlin.jvm.internal" ) -> {
2205
2237
2206
2238
if (c.valueArgumentsCount != 1 ) {
2207
- logger.errorElement(" Expected to find only one argument for a kotlin.jvm.internal.<unsafe-coerce>() call" , c)
2239
+ logger.errorElement(" Expected to find one argument for a kotlin.jvm.internal.<unsafe-coerce>() call, but found ${c.valueArgumentsCount} " , c)
2208
2240
return
2209
2241
}
2210
2242
2211
2243
if (c.typeArgumentsCount != 2 ) {
2212
- logger.errorElement(" Expected to find two type arguments for a kotlin.jvm.internal.<unsafe-coerce>() call" , c)
2244
+ logger.errorElement(" Expected to find two type arguments for a kotlin.jvm.internal.<unsafe-coerce>() call, but found ${c.typeArgumentsCount} " , c)
2245
+ return
2246
+ }
2247
+ val valueArg = c.getValueArgument(0 )
2248
+ if (valueArg == null ) {
2249
+ logger.errorElement(" Cannot find value argument for a kotlin.jvm.internal.<unsafe-coerce>() call" , c)
2250
+ return
2251
+ }
2252
+ val typeArg = c.getTypeArgument(1 )
2253
+ if (typeArg == null ) {
2254
+ logger.errorElement(" Cannot find type argument for a kotlin.jvm.internal.<unsafe-coerce>() call" , c)
2213
2255
return
2214
2256
}
2215
2257
@@ -2221,8 +2263,8 @@ open class KotlinFileExtractor(
2221
2263
tw.writeHasLocation(id, locId)
2222
2264
tw.writeCallableEnclosingExpr(id, callable)
2223
2265
tw.writeStatementEnclosingExpr(id, enclosingStmt)
2224
- extractTypeAccessRecursive(c.getTypeArgument( 1 ) !! , locId, id, 0 , callable, enclosingStmt)
2225
- extractExpressionExpr(c.getValueArgument( 0 ) !! , callable, id, 1 , enclosingStmt)
2266
+ extractTypeAccessRecursive(typeArg , locId, id, 0 , callable, enclosingStmt)
2267
+ extractExpressionExpr(valueArg , callable, id, 1 , enclosingStmt)
2226
2268
}
2227
2269
isBuiltinCallInternal(c, " dataClassArrayMemberToString" ) -> {
2228
2270
val arrayArg = c.getValueArgument(0 )
0 commit comments