-
Notifications
You must be signed in to change notification settings - Fork 2k
C# 14: Null conditional assignments. #21158
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 6 commits
9894993
b061c4d
0bf0cba
4ba8923
f0135e9
5942edf
ab432ec
812fdbe
3d988e8
bd1c6e6
86198e3
beb7750
33fc2ba
7ae2b76
7ff1c12
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 |
|---|---|---|
|
|
@@ -43,6 +43,12 @@ private Expr maybeNullExpr(Expr reason) { | |
| ) | ||
| or | ||
| result.(NullCoalescingExpr).getRightOperand() = maybeNullExpr(reason) | ||
| or | ||
| result = | ||
| any(QualifiableExpr qe | | ||
| qe.isConditional() and | ||
| qe.getQualifier() = maybeNullExpr(reason) | ||
|
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. Is this actually needed? I would think that an expression like
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. Yes, if
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. What I meant was why not result = any(QualifiableExpr qe | qe.isConditional() and reason = qe.getQualifier())That should give us strictly more results, and I would assume that any
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. That is somewhat less conservative. It means that stuff like void M1(object o)
{
var t = o?.GetType();
Console.WriteLine(t.FullName);
}gets flagged (which is good), but it also means that we introduce false positives in cases like void M2()
{
var o = new object();
var t = o?.GetType();
Console.WriteLine(t.FullName); // GOOD
}Maybe that is acceptable for a "maybe" query (to consider the intent of the use of
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. I would think that was OK; if the qualifier cannot be null then there is no need to use |
||
| ) | ||
| } | ||
|
|
||
| /** An expression that may be `null`. */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.