Fix emit of param-nullchecking on async methods#58822
Merged
RikkiGibson merged 4 commits intodotnet:mainfrom Jan 18, 2022
Merged
Fix emit of param-nullchecking on async methods#58822RikkiGibson merged 4 commits intodotnet:mainfrom
RikkiGibson merged 4 commits intodotnet:mainfrom
Conversation
4bdece3 to
8681870
Compare
RikkiGibson
commented
Jan 13, 2022
|
|
||
| var builtBody = bodyBuilder.ToImmutableAndFree(); | ||
| ImmutableArray<BoundStatement> newBody = LocalRewriter.TryConstructNullCheckedStatementList(method.Parameters, builtBody, F); | ||
| return newBody.IsDefault ? F.Block(builtBody) : F.Block(ImmutableArray.Create(stateMachineVariable), newBody); |
Member
Author
There was a problem hiding this comment.
The ImmutableArray here specifically was the cause of the crash. newBody already contained a block with the stateMachineVariable in it, so adding it again here made us crash in code generation.
cston
reviewed
Jan 13, 2022
| } | ||
| SetGlobalErrorIfTrue(nullCheckStatements.HasErrors() || diagnosticsThisMethod.HasAnyErrors()); | ||
|
|
||
| if (_emitMethodBodies && !diagnosticsThisMethod.HasAnyErrors() && !_globalHasErrors) |
Contributor
cston
reviewed
Jan 13, 2022
cston
reviewed
Jan 13, 2022
cston
reviewed
Jan 13, 2022
jcouv
reviewed
Jan 13, 2022
src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenNullCheckedParameterTests.cs
Show resolved
Hide resolved
jcouv
approved these changes
Jan 13, 2022
Member
jcouv
left a comment
There was a problem hiding this comment.
LGTM Thanks (iteration 2) with a test suggestion to consider
cston
reviewed
Jan 13, 2022
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.cs
Outdated
Show resolved
Hide resolved
cston
reviewed
Jan 13, 2022
src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenNullCheckedParameterTests.cs
Outdated
Show resolved
Hide resolved
cston
approved these changes
Jan 18, 2022
Closed
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.
Closes #58796
Related to #36024
Spec update: dotnet/csharplang#5642
It seems we neglected to test the feature in combination with regular async methods. We do have some existing coverage for async iterators.
I found it was simplest to insert null checks after the last rewriting pass for both regular and synthesized methods. I found that when I added the checks before running the iterator rewriter they would actually get dropped in some scenarios.