-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Bind lambda in yield return
despite errors
#75660
Conversation
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
|
||
// NOTE: it's possible that more than one of these conditions is satisfied and that | ||
// we won't report the syntactically innermost. However, dev11 appears to check | ||
// them in this order, regardless of syntactic nesting (StatementBinder::bindYield). | ||
if (this.Flags.Includes(BinderFlags.InFinallyBlock)) | ||
{ | ||
Error(diagnostics, ErrorCode.ERR_BadYieldInFinally, node.YieldKeyword); | ||
hasErrors = true; |
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.
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.
I woke up this morning with the same thought, but you'd already reviewed. Thanks
} | ||
|
||
CheckRequiredLangVersionForIteratorMethods(node, diagnostics); | ||
|
||
if (argument != null) |
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.
"""; | ||
var comp = CreateCompilation(src, targetFramework: TargetFramework.Net80); | ||
comp.VerifyDiagnostics( | ||
// (7,63): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. |
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.
Done with review pass (commit 3) |
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.
LGTM (commit 6)
@dotnet/roslyn-compiler for second review. Thanks |
Fixes #68027
The problem was that
BindYieldReturnStatement
gave up too easily on trying to convert the lambda. Without conversion, the lambda state didn't account for the target delegate type, which provides the parameter types for the lambda. So the lookup result for identifiers
(which finds a candidate for type in local declarations await
) lacked a type.In fixing this, I noticed that the binding diagnostics for the
yield return
and thereturn
scenarios were different.The
ERR_BadSKknown
andERR_IllegalStatement
binding errors were now reported in theyield return
scenario, but not in thereturn
scenario.In
BindYieldReturn
, we useGenerateConversionForAssignment
which collects the conversion diagnostics fromGenerateImplicitConversionError
unlessexpression.HasAnyErrors && expression.Kind != BoundKind.UnboundLambda
.In
BindReturn
, we useCreateReturnConversion
, which skipped reporting fromGenerateImplicitConversionError
ifargument.HasAnyErrors
.So I made an adjustment to the
return
binding logic to also report the diagnostics from converting/binding the lambda (BoundKind.UnboundLambda
).