Tolerate nullable references to anonymous classes

This also adds a test case illustrating when this can arise
This commit is contained in:
Chris Smowton
2022-03-17 17:54:31 +00:00
committed by Ian Lynagh
parent 8d6ae50d21
commit c0f3988aaa
9 changed files with 74 additions and 19 deletions

View File

@@ -363,19 +363,14 @@ open class KotlinUsesExtractor(
classLabelResult.shortName)
}
fun useAnonymousClass(c: IrClass): TypeResults {
var res = tw.lm.anonymousTypeMapping[c]
if (res == null) {
val javaResult = TypeResult(tw.getFreshIdLabel<DbClass>(), "", "")
val kotlinResult = TypeResult(tw.getFreshIdLabel<DbKt_notnull_type>(), "", "")
tw.writeKt_notnull_types(kotlinResult.id, javaResult.id)
res = TypeResults(javaResult, kotlinResult)
tw.lm.anonymousTypeMapping[c] = res
fun useAnonymousClass(c: IrClass) =
tw.lm.anonymousTypeMapping.getOrPut(c) {
TypeResults(
TypeResult(tw.getFreshIdLabel<DbClass>(), "", ""),
TypeResult(fakeKotlinType(), "TODO", "TODO")
)
}
return res
}
fun fakeKotlinType(): Label<out DbKt_type> {
val fakeKotlinPackageId: Label<DbPackage> = tw.getLabelFor("@\"FakeKotlinPackage\"", {
tw.writePackages(it, "fake.kotlin")
@@ -396,9 +391,6 @@ open class KotlinUsesExtractor(
if (args?.isNotEmpty() == true) {
logger.error("Anonymous class with unexpected type arguments")
}
if (hasQuestionMark) {
logger.error("Unexpected nullable anonymous class")
}
return useAnonymousClass(c)
}