From 565e780285c49ac488904c215ea73472b76ccaa6 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Tue, 8 Oct 2024 15:18:15 +0100 Subject: [PATCH] KE2: Handle null types (emit errortypes) --- .../src/main/kotlin/KotlinFileExtractor.kt | 10 +++------- .../src/main/kotlin/entities/Types.kt | 17 +++++++++-------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt b/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt index 821ef4bf026..968289a6696 100644 --- a/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt +++ b/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt @@ -4864,13 +4864,9 @@ OLD: KE1 override fun stmt(e: KtExpression, callable: Label): StmtParent { val id = tw.getFreshIdLabel() val et = e.expressionType - if (et != null) { - val type = useType(et) - val locId = tw.getLocation(e) - tw.writeExprs_stmtexpr(id, type.javaResult.id, parent, idx) - } else { - logger.errorElement("Unexpected null type: ${e.javaClass}", e) - } + val type = useType(et) + val locId = tw.getLocation(e) + tw.writeExprs_stmtexpr(id, type.javaResult.id, parent, idx) /* OLD: KE1 tw.writeExprsKotlinType(id, type.kotlinResult.id) diff --git a/java/kotlin-extractor2/src/main/kotlin/entities/Types.kt b/java/kotlin-extractor2/src/main/kotlin/entities/Types.kt index 7b297da0971..f366edcea48 100644 --- a/java/kotlin-extractor2/src/main/kotlin/entities/Types.kt +++ b/java/kotlin-extractor2/src/main/kotlin/entities/Types.kt @@ -11,8 +11,12 @@ private fun KotlinUsesExtractor.useClassType( return TypeResults(javaResult, kotlinResult) } -fun KotlinUsesExtractor.useType(t: KaType, context: TypeContext = TypeContext.OTHER): TypeResults { +fun KotlinUsesExtractor.useType(t: KaType?, context: TypeContext = TypeContext.OTHER): TypeResults { when (t) { + null -> { + logger.error("Unexpected null type") + return extractErrorType() + } is KaClassType -> return useClassType(t) else -> TODO() } @@ -28,14 +32,12 @@ fun KotlinUsesExtractor.useType(t: KaType, context: TypeContext = TypeContext.OT */ } -/* -OLD: KE1 -private fun extractJavaErrorType(): TypeResult { +private fun KotlinUsesExtractor.extractJavaErrorType(): TypeResult { val typeId = tw.getLabelFor("@\"errorType\"") { tw.writeError_type(it) } - return TypeResult(typeId, "", "") + return TypeResult(typeId /* TODO , "", "" */) } -private fun extractErrorType(): TypeResults { +private fun KotlinUsesExtractor.extractErrorType(): TypeResults { val javaResult = extractJavaErrorType() val kotlinTypeId = tw.getLabelFor("@\"errorKotlinType\"") { @@ -43,10 +45,9 @@ private fun extractErrorType(): TypeResults { } return TypeResults( javaResult, - TypeResult(kotlinTypeId, "", "") + TypeResult(kotlinTypeId /* TODO , "", "" */) ) } -*/ // TODO fun KotlinUsesExtractor.fakeKotlinType(): Label {