Merge pull request #9806 from igfoo/igfoo/useType

Kotlin: Extract an ErrorType if we fail to correctly extract a type
This commit is contained in:
Ian Lynagh
2022-07-12 13:45:04 +01:00
committed by GitHub
9 changed files with 4670 additions and 2100 deletions

View File

@@ -111,14 +111,26 @@ open class KotlinUsesExtractor(
}
data class TypeResults(val javaResult: TypeResult<DbType>, val kotlinResult: TypeResult<DbKt_type>)
fun useType(t: IrType, context: TypeContext = TypeContext.OTHER) =
fun useType(t: IrType, context: TypeContext = TypeContext.OTHER): TypeResults {
when(t) {
is IrSimpleType -> useSimpleType(t, context)
is IrSimpleType -> return useSimpleType(t, context)
else -> {
logger.error("Unrecognised IrType: " + t.javaClass)
TypeResults(TypeResult(fakeLabel(), "unknown", "unknown"), TypeResult(fakeLabel(), "unknown", "unknown"))
return extractErrorType()
}
}
}
private fun extractErrorType(): TypeResults {
val typeId = tw.getLabelFor<DbErrortype>("@\"errorType\"") {
tw.writeError_type(it)
}
val kotlinTypeId = tw.getLabelFor<DbKt_nullable_type>("@\"errorKotlinType\"") {
tw.writeKt_nullable_types(it, typeId)
}
return TypeResults(TypeResult(typeId, null, "<CodeQL error type>"),
TypeResult(kotlinTypeId, null, "<CodeQL error type>"))
}
fun getJavaEquivalentClass(c: IrClass) =
getJavaEquivalentClassId(c)?.let { pluginContext.referenceClass(it.asSingleFqName()) }?.owner