Fix faulty cast in state machine rewriter#55063
Merged
333fred merged 1 commit intodotnet:mainfrom Jul 23, 2021
Merged
Conversation
HoistRefInitialization assumed that the declarator syntax for locals would always be an await expression, but this is not true for switch expressions. CalculateLocalSyntaxOffset already correctly handles switch expressions, so we just needed to update this call site. I also inspected any other calls to CalculateLocalSyntaxOffset to make sure that nothing else was making such an assumption, but I didn't see any that are concerning.
Member
Author
|
@dotnet/roslyn-compiler for a quick review. |
RikkiGibson
reviewed
Jul 23, 2021
| { | ||
| awaitSyntaxOpt = (AwaitExpressionSyntax)local.GetDeclaratorSyntax(); | ||
| awaitSyntaxOpt = local.GetDeclaratorSyntax(); | ||
| Debug.Assert(awaitSyntaxOpt.IsKind(SyntaxKind.AwaitExpression) || awaitSyntaxOpt.IsKind(SyntaxKind.SwitchExpression)); |
Member
There was a problem hiding this comment.
Could you help me understand why only await and switch are expected to be encountered here? For example if I had GetRef() = flag ? await GetAsync() : 42 would I hit this assert?
Member
Author
There was a problem hiding this comment.
You would not hit this assert. There's some differences in the syntaxes used by the SpillSequenceSpiller here, and the local in the case you mentioned would be the await expression, not the ternary. I'd need to dig more into the local rewriter to tell you the exact reasons for that difference.
RikkiGibson
approved these changes
Jul 23, 2021
Member
Author
|
@dotnet/roslyn-compiler for a second review. |
chsienki
approved these changes
Jul 23, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HoistRefInitialization assumed that the declarator syntax for locals would always be an await expression, but this is not true for switch expressions. CalculateLocalSyntaxOffset already correctly handles switch expressions, so we just needed to update this call site. I also inspected any other calls to CalculateLocalSyntaxOffset to make sure that nothing else was making such an assumption, but I didn't see any that are concerning.
Fixes #51930.