Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ab4335

Browse files
tamasvajkigfoo
authored andcommitted
Add some error handling
1 parent a598c7f commit 8ab4335

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,8 +2917,22 @@ open class KotlinFileExtractor(
29172917
}
29182918

29192919
val functionType = if (e.argument.type.isKFunction()) {
2920-
// todo: add error handling to the below
2921-
getFunctionalInterfaceType((e.argument.type as IrSimpleType).arguments.filterIsInstance<IrTypeProjection>().map { it.type })
2920+
val st = e.argument.type as? IrSimpleType
2921+
if (st == null) {
2922+
logger.errorElement("Expected to find a simple type in SAM conversion.", e)
2923+
return
2924+
}
2925+
2926+
val typeArgs = mutableListOf<IrType>()
2927+
for (arg in st.arguments) {
2928+
if (arg !is IrTypeProjection) {
2929+
logger.errorElement("Expected to find only type projections in SAM conversion.", e)
2930+
return
2931+
}
2932+
typeArgs.add(arg.type)
2933+
}
2934+
2935+
getFunctionalInterfaceType(typeArgs)
29222936
} else {
29232937
e.argument.type
29242938
}

0 commit comments

Comments
 (0)