Skip to content
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

Merged
merged 6 commits into from
Oct 30, 2024
Merged

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Oct 29, 2024

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 identifier s (which finds a candidate for type in local declaration s await) lacked a type.

In fixing this, I noticed that the binding diagnostics for the yield return and the return scenarios were different.
The ERR_BadSKknown and ERR_IllegalStatement binding errors were now reported in the yield return scenario, but not in the return scenario.
In BindYieldReturn, we use GenerateConversionForAssignment which collects the conversion diagnostics from GenerateImplicitConversionError unless expression.HasAnyErrors && expression.Kind != BoundKind.UnboundLambda.
In BindReturn, we use CreateReturnConversion, which skipped reporting from GenerateImplicitConversionError if argument.HasAnyErrors.
So I made an adjustment to the return binding logic to also report the diagnostics from converting/binding the lambda (BoundKind.UnboundLambda).

@jcouv jcouv self-assigned this Oct 29, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Oct 29, 2024
@jcouv jcouv marked this pull request as ready for review October 29, 2024 04:06
@jcouv jcouv requested a review from a team as a code owner October 29, 2024 04:06
@jcouv jcouv marked this pull request as draft October 29, 2024 13:12
@AlekseyTs
Copy link
Contributor

/azp run

Copy link

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;
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasErrors = true;

Why would we want to disable conversion binding for this and the other modified code paths. It feels to me that the conversion checks and the "unsupported" context checks are orthogonal, therefore cannot be considered as cascading for one another #Closed

Copy link
Member Author

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)
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argument != null

Is this condition ever false? #Closed

""";
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.
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning CS1998

Consider suppressing this warning if it is not a goal of the test to verify its presence #Closed

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 3)

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 6)

@jcouv jcouv marked this pull request as ready for review October 29, 2024 17:39
@jcouv
Copy link
Member Author

jcouv commented Oct 29, 2024

@dotnet/roslyn-compiler for second review. Thanks

@RikkiGibson RikkiGibson self-assigned this Oct 30, 2024
@jcouv jcouv merged commit 9e862f1 into dotnet:main Oct 30, 2024
24 checks passed
@jcouv jcouv deleted the yield-lambda branch October 30, 2024 22:13
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IntelliSense cannot detect IAsyncEnumerable's yield return type when that parameter is used
4 participants