@@ -142,6 +142,7 @@ private module GuardsInput implements
142142 }
143143 }
144144
145+ pragma [ nomagic]
145146 predicate equalityTest ( Expr eqtest , Expr left , Expr right , boolean polarity ) {
146147 exists ( ComparisonTest ct |
147148 ct .getExpr ( ) = eqtest and
@@ -410,6 +411,21 @@ private predicate typePattern(PatternMatch pm, TypePatternExpr tpe, Type t) {
410411 t = pm .getExpr ( ) .getType ( )
411412}
412413
414+ private predicate dereferenceableExpr ( Expr e , boolean isNullableType ) {
415+ exists ( Type t | t = e .getType ( ) |
416+ t instanceof NullableType and
417+ isNullableType = true
418+ or
419+ t instanceof RefType and
420+ isNullableType = false
421+ )
422+ or
423+ exists ( Expr parent |
424+ dereferenceableExpr ( parent , isNullableType ) and
425+ e = getNullEquivParent ( parent )
426+ )
427+ }
428+
413429/**
414430 * An expression that evaluates to a value that can be dereferenced. That is,
415431 * an expression that may evaluate to `null`.
@@ -418,21 +434,12 @@ class DereferenceableExpr extends Expr {
418434 private boolean isNullableType ;
419435
420436 DereferenceableExpr ( ) {
421- exists ( Expr e , Type t |
422- // There is currently a bug in the extractor: the type of `x?.Length` is
423- // incorrectly `int`, while it should have been `int?`. We apply
424- // `getNullEquivParent()` as a workaround
425- this = getNullEquivParent * ( e ) and
426- t = e .getType ( ) and
427- not this instanceof SwitchCaseExpr and
428- not this instanceof PatternExpr
429- |
430- t instanceof NullableType and
431- isNullableType = true
432- or
433- t instanceof RefType and
434- isNullableType = false
435- )
437+ // There is currently a bug in the extractor: the type of `x?.Length` is
438+ // incorrectly `int`, while it should have been `int?`. We apply
439+ // `getNullEquivParent()` as a workaround
440+ dereferenceableExpr ( this , isNullableType ) and
441+ not this instanceof SwitchCaseExpr and
442+ not this instanceof PatternExpr
436443 }
437444
438445 /** Holds if this expression has a nullable type `T?`. */
0 commit comments