-
Notifications
You must be signed in to change notification settings - Fork 2k
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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name might be a bit misleading at the pattern can have "mentions" (and thus containing)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I was thinking "contains" in the sense that the pattern represents a set of values. But yes, I'll change it, |
||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe consider elaborating the comment above. Do we need the dual
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. Just because a pattern will match
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes, that is of course correct. There is some overlap in this disjunct with should the above be changed to only handle
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, but probably doesn't matter. Regardless, this is just a stepping stone - I'm working on a shared Guards instantiation in a separate branch where this will be tweaked anyway.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent! Once again, thank you! |
||
| isNull = false | ||
| or | ||
| exists(TypePatternExpr tpe | | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.