-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C#: Bugfix for nullguards for complex patterns. #20449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -273,6 +273,31 @@ module AbstractValues { | |
|
|
||
| private import AbstractValues | ||
|
|
||
| /** Gets the value resulting from matching `null` against `pat`. */ | ||
| private boolean patternContainsNull(PatternExpr pat) { | ||
|
||
| pat instanceof NullLiteral and result = true | ||
| or | ||
| not pat instanceof NullLiteral and | ||
| not pat instanceof NotPatternExpr and | ||
| not pat instanceof OrPatternExpr and | ||
| not pat instanceof AndPatternExpr and | ||
| result = false | ||
| or | ||
| result = patternContainsNull(pat.(NotPatternExpr).getPattern()).booleanNot() | ||
| or | ||
| exists(OrPatternExpr ope | pat = ope | | ||
| result = | ||
| patternContainsNull(ope.getLeftOperand()) | ||
| .booleanOr(patternContainsNull(ope.getRightOperand())) | ||
| ) | ||
| or | ||
| exists(AndPatternExpr ape | pat = ape | | ||
| result = | ||
| patternContainsNull(ape.getLeftOperand()) | ||
| .booleanAnd(patternContainsNull(ape.getRightOperand())) | ||
| ) | ||
| } | ||
|
|
||
| pragma[nomagic] | ||
| private predicate typePattern(PatternMatch pm, TypePatternExpr tpe, Type t) { | ||
| tpe = pm.getPattern() and | ||
|
|
@@ -362,8 +387,7 @@ class DereferenceableExpr extends Expr { | |
| isNull = branch | ||
| or | ||
| // E.g. `x is string` or `x is ""` | ||
| not pm.getPattern() instanceof NullLiteral and | ||
| branch = true and | ||
| branch.booleanNot() = patternContainsNull(pm.getPattern()) and | ||
|
||
| isNull = false | ||
| or | ||
| exists(TypePatternExpr tpe | | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.