-
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
Avoid reporting ref safety errors for discard assignments #65693
Conversation
1bccb86
to
d1f345d
Compare
@@ -182,7 +182,7 @@ internal override BoundStatement BindForEachDeconstruction(BindingDiagnosticBag | |||
ExpressionSyntax variables = ((ForEachVariableStatementSyntax)_syntax).Variable; | |||
|
|||
// Tracking narrowest safe-to-escape scope by default, the proper val escape will be set when doing full binding of the foreach statement | |||
var valuePlaceholder = new BoundDeconstructValuePlaceholder(_syntax.Expression, variableSymbol: null, this.LocalScopeDepth, inferredType.Type ?? CreateErrorType("var")); | |||
var valuePlaceholder = new BoundDeconstructValuePlaceholder(_syntax.Expression, variableSymbol: null, this.LocalScopeDepth, isDiscardExpression: false, inferredType.Type ?? CreateErrorType("var")); |
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 believe this placeholder is for the expression rather than iteration variables.
{ | ||
static void F(ref R r) | ||
{ | ||
foreach ((R r0, _) in new Enumerable1()) break; |
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.
Consider adding a non-deconstruction variant: foreach (var _ in ...)
or foreach (ref var _ in ...)
#Closed
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.
Also, I liked how for deconstruction tests you added the equivalent lowered version (calling Deconstruct
). Consider doing the same for foreach-deconstruction scenarios, adding equivalent lowered code.
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 (iteration 4)
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 Thanks (iteration 6)
Fixes #65522
Fixes #65651
Also fixes an additional issue where the compiler was reporting a ref safety error for deconstruction into an explicitly typed discard - see
RefEscapingTests.Discard_03
: