mirror of
https://github.com/github/codeql.git
synced 2025-12-22 19:56:32 +01:00
Kotlin extractor: use special <nulltype> for null literals
This matches the Java extractor's treatment of these literals, and so enables dataflow type-tracking to avoid special-casing Kotlin. Natively, Kotlin would regard this as kotlin.Nothing?, the type that can only contain null (kotlin.Nothing without a ? can take nothing at all), which gets Java-ified as java.lang.Void, and this will continue to be used when a null type has to be "boxed", as in representing substituted generic constraints with no possible type.
This commit is contained in:
@@ -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(
|
||||
"@\"type;$nullTypeName\"",
|
||||
{ tw.writePrimitives(it, nullTypeName) }
|
||||
)
|
||||
tw.writeExprs_nullliteral(it, javaNullType, parent, idx)
|
||||
tw.writeExprsKotlinType(it, type.kotlinResult.id)
|
||||
extractExprContext(it, locId, callable, enclosingStmt)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user