Skip to content

Commit

Permalink
Merge pull request #17890 from smowton/smowton/fix/kotlin-use-nulltype
Browse files Browse the repository at this point in the history
Kotlin extractor: use special <nulltype> for null literals
  • Loading branch information
smowton authored Nov 11, 2024
2 parents bf07aa1 + 81ff394 commit 89a2f0d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 8 additions & 1 deletion java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5745,7 +5745,14 @@ open class KotlinFileExtractor(
) =
exprIdOrFresh<DbNullliteral>(overrideId).also {
val type = useType(t)
tw.writeExprs_nullliteral(it, type.javaResult.id, parent, idx)
// Match Java by using a special <nulltype> for nulls, rather than Kotlin's view of this which is
// kotlin.Nothing?, the type that can only contain null.
val nullTypeName = "<nulltype>"
val javaNullType = tw.getLabelFor<DbPrimitive>(
"@\"type;$nullTypeName\"",
{ tw.writePrimitives(it, nullTypeName) }
)
tw.writeExprs_nullliteral(it, javaNullType, parent, idx)
tw.writeExprsKotlinType(it, type.kotlinResult.id)
extractExprContext(it, locId, callable, enclosingStmt)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
| generic_anonymous.kt:13:27:13:47 | get(...) | int |
| generic_anonymous.kt:13:40:13:40 | i | int |
| generic_anonymous.kt:17:9:17:29 | T0 | T0 |
| generic_anonymous.kt:17:26:17:29 | null | Void |
| generic_anonymous.kt:17:26:17:29 | null | <nulltype> |
| generic_anonymous.kt:21:9:21:29 | T1 | T1 |
| generic_anonymous.kt:21:26:21:29 | null | Void |
| generic_anonymous.kt:21:26:21:29 | null | <nulltype> |
| generic_anonymous.kt:24:5:32:5 | Unit | Unit |
| generic_anonymous.kt:25:9:31:9 | Unit | Unit |
| generic_anonymous.kt:26:13:26:37 | <Stmt> | new Object(...) { ... } |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
| generic_anonymous.kt:13:27:13:47 | get(...) | int |
| generic_anonymous.kt:13:40:13:40 | i | int |
| generic_anonymous.kt:17:9:17:29 | T0 | T0 |
| generic_anonymous.kt:17:26:17:29 | null | Void |
| generic_anonymous.kt:17:26:17:29 | null | <nulltype> |
| generic_anonymous.kt:21:9:21:29 | T1 | T1 |
| generic_anonymous.kt:21:26:21:29 | null | Void |
| generic_anonymous.kt:21:26:21:29 | null | <nulltype> |
| generic_anonymous.kt:24:5:32:5 | Unit | Unit |
| generic_anonymous.kt:25:9:31:9 | Unit | Unit |
| generic_anonymous.kt:26:13:26:37 | <Stmt> | new Object(...) { ... } |
Expand Down

0 comments on commit 89a2f0d

Please sign in to comment.