Fix hasNullCase

This commit is contained in:
Chris Smowton
2023-11-15 15:03:42 +00:00
parent 480781b049
commit de2b98f4a1
4 changed files with 14 additions and 3 deletions

View File

@@ -1547,7 +1547,10 @@ class SwitchExpr extends Expr, StmtParent, @switchexpr {
}
/** Holds if this switch has a case handling a null literal. */
predicate hasNullCase() { this.getAConstCase().getValue(_) instanceof NullLiteral }
predicate hasNullCase() {
this.getAConstCase().getValue(_) instanceof NullLiteral or
this.getACase() instanceof NullDefaultCase
}
/** Gets a printable representation of this expression. */
override string toString() { result = "switch (...)" }

View File

@@ -413,7 +413,10 @@ class SwitchStmt extends Stmt, @switchstmt {
Expr getExpr() { result.getParent() = this }
/** Holds if this switch has a case handling a null literal. */
predicate hasNullCase() { this.getAConstCase().getValue(_) instanceof NullLiteral }
predicate hasNullCase() {
this.getAConstCase().getValue(_) instanceof NullLiteral or
this.getACase() instanceof NullDefaultCase
}
override string pp() { result = "switch (...)" }