Skip to content

Commit fa20075

Browse files
committed
C#: Review fix and simplification.
1 parent 4f6528a commit fa20075

File tree

1 file changed

+1
-26
lines changed
  • csharp/ql/lib/semmle/code/csharp/controlflow

1 file changed

+1
-26
lines changed

csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ deprecated module AbstractValues {
374374
}
375375
}
376376

377-
// private import AbstractValues
378377
/** Gets the value resulting from matching `null` against `pat`. */
379378
private boolean patternMatchesNull(PatternExpr pat) {
380379
pat instanceof NullLiteral and result = true
@@ -432,35 +431,11 @@ class DereferenceableExpr extends Expr {
432431
/** Holds if this expression has a nullable type `T?`. */
433432
predicate hasNullableType() { isNullableType = true }
434433

435-
/**
436-
* Gets an expression that tests via nullness whether this expression is `null`.
437-
*
438-
* If the returned expression evaluates to `null` (`v.isNullValue()`) or evaluates to
439-
* non-`null` (`not v.isNullValue()`), then this expression is guaranteed to be `null`
440-
* if `isNull` is true, and non-`null` if `isNull` is false.
441-
*
442-
* For example, if `x` evaluates to `null` in `x ?? y` then `y` is evaluated, and
443-
* `x` is guaranteed to be `null`.
444-
*/
445-
private Expr getANullnessNullCheck(GuardValue v, boolean isNull) {
446-
exists(NullnessCompletion c | c.isValidFor(this) |
447-
result = this and
448-
if c.isNull()
449-
then (
450-
v.isNullValue() and
451-
isNull = true
452-
) else (
453-
v.isNonNullValue() and
454-
isNull = false
455-
)
456-
)
457-
}
458-
459434
/** Holds if `guard` suggests that this expression may be `null`. */
460435
predicate guardSuggestsMaybeNull(Guards::Guard guard) {
461436
not nonNullValueImplied(this) and
462437
(
463-
guard = this.getANullnessNullCheck(_, true)
438+
exists(NullnessCompletion c | c.isValidFor(this) and c.isNull() and guard = this)
464439
or
465440
LogicInput::additionalNullCheck(guard, _, this, true)
466441
or

0 commit comments

Comments
 (0)