Merge pull request #9149 from tamasvajk/kotlin-maybe-null

Kotlin: Exclude operands of `NotNullExpr` from NullMaybe query
This commit is contained in:
Tamás Vajk
2022-05-17 08:43:24 +02:00
committed by GitHub
4 changed files with 11 additions and 1 deletions

View File

@@ -21,6 +21,8 @@ from VarAccess access, SsaSourceVariable var, string msg, Expr reason
where
nullDeref(var, access, msg, reason) and
// Exclude definite nulls here, as these are covered by `NullAlways.ql`.
not alwaysNullDeref(var, access)
not alwaysNullDeref(var, access) and
// Kotlin enforces this already:
not access.getLocation().getFile().isKotlinSourceFile()
select access, "Variable $@ may be null here " + msg + ".", var.getVariable(),
var.getVariable().getName(), reason, "this"

View File

@@ -0,0 +1 @@
Likely Bugs/Nullness/NullMaybe.ql

View File

@@ -0,0 +1,7 @@
fun fn(b: Boolean) {
var d: Double? = null
if (b) {
d = 1.0
}
println(d!!)
}