mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
Merge pull request #9149 from tamasvajk/kotlin-maybe-null
Kotlin: Exclude operands of `NotNullExpr` from NullMaybe query
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Likely Bugs/Nullness/NullMaybe.ql
|
||||
7
java/ql/test/kotlin/query-tests/NullMaybe/Test.kt
Normal file
7
java/ql/test/kotlin/query-tests/NullMaybe/Test.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
fun fn(b: Boolean) {
|
||||
var d: Double? = null
|
||||
if (b) {
|
||||
d = 1.0
|
||||
}
|
||||
println(d!!)
|
||||
}
|
||||
Reference in New Issue
Block a user