-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Warn for yield return
in lock
#72755
Changes from 5 commits
5ec2c2b
654d458
eafc594
5813209
b201c76
43f9fe4
e86ea6a
7fa7cad
d64ce2a
0d21cce
e7bdd89
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 |
---|---|---|
|
@@ -55,8 +55,9 @@ internal override BoundStatement BindLockStatementParts(BindingDiagnosticBag dia | |
hasErrors = true; | ||
} | ||
|
||
if (exprType?.IsWellKnownTypeLock() == true && | ||
TryFindLockTypeInfo(exprType, diagnostics, exprSyntax) is { } lockTypeInfo) | ||
bool isLockObjectBased = exprType?.IsWellKnownTypeLock() == true; | ||
if (isLockObjectBased && | ||
TryFindLockTypeInfo(exprType!, diagnostics, exprSyntax) is { } lockTypeInfo) | ||
{ | ||
CheckFeatureAvailability(exprSyntax, MessageID.IDS_FeatureLockObject, diagnostics); | ||
|
||
|
@@ -73,8 +74,18 @@ internal override BoundStatement BindLockStatementParts(BindingDiagnosticBag dia | |
errorCode: ErrorCode.ERR_BadSpecialByRefLock); | ||
} | ||
|
||
BoundStatement stmt = originalBinder.BindPossibleEmbeddedStatement(_syntax.Statement, diagnostics); | ||
var needsFilterDiagnostics = isLockObjectBased && diagnostics.AccumulatesDiagnostics; | ||
var bodyDiagnostics = needsFilterDiagnostics ? BindingDiagnosticBag.GetInstance(template: diagnostics) : diagnostics; | ||
|
||
BoundStatement stmt = originalBinder.BindPossibleEmbeddedStatement(_syntax.Statement, bodyDiagnostics); | ||
Debug.Assert(this.Locals.IsDefaultOrEmpty); | ||
|
||
if (needsFilterDiagnostics) | ||
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. 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.
|
||
{ | ||
bodyDiagnostics.CopyFilteredToAndFree(diagnostics, | ||
static code => code is not ErrorCode.WRN_BadYieldInLock); | ||
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. While it feels tempting to always report a warning and then filter it out, I would prefer us to not report the warning in the first place. A diagnostic filtering is an exception rather than a usual way of doing things. In this case, I think, we can avoid it. See, for example, how a set of 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. Another thing to consider is to simplify and not attempt to suppress the warning at all. I do not think it is going to lead to any confusion and the problem with the lock object itself is a separate matter. |
||
} | ||
|
||
return new BoundLockStatement(_syntax, expr, stmt, hasErrors); | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is very easy to make a mistake and start adding checks for other errors (not warnings) in the
else
of thisif
statement. Consider adding a comment right above it saying that all error conditions should be checked outside itselse
if one is added in the future. #Closed