Allow ref initializers for ref fields#64817
Merged
cston merged 4 commits intodotnet:mainfrom Oct 22, 2022
Merged
Conversation
fcfe669 to
7fe1bd7
Compare
7fe1bd7 to
d1381c7
Compare
Contributor
Author
|
@dotnet/roslyn-compiler, please review. |
jcouv
reviewed
Oct 20, 2022
jcouv
reviewed
Oct 20, 2022
jcouv
reviewed
Oct 20, 2022
jcouv
reviewed
Oct 20, 2022
Member
jcouv
left a comment
There was a problem hiding this comment.
Done with review pass (iteration 1)
RikkiGibson
reviewed
Oct 21, 2022
| ref byte _f1 = ref F(stackalloc byte[1]); | ||
| ref readonly byte _f2 = ref F(stackalloc byte[1]); | ||
| public R(object o) { } | ||
| static ref T F<T>(Span<T> s) => throw null; |
Member
There was a problem hiding this comment.
consider also testing a case where the span is scoped, so the initializer calling F() becomes legal.
consider also testing a case where an out var can escape through the return of a call, a la the following
ref struct RS
{
ref byte rb = ref M(out var b);
public RS() { }
static ref byte M([UnscopedRef] out byte b)
{
b = 42;
return ref b;
}
}
jcouv
reviewed
Oct 21, 2022
| static ref T F<T>(scoped Span<T> s) => throw null; | ||
| }"; | ||
| var comp = CreateCompilation(source, targetFramework: TargetFramework.Net70); | ||
| comp.VerifyEmitDiagnostics(); |
Member
There was a problem hiding this comment.
nit: consider verifying execution too #Resolved
RikkiGibson
approved these changes
Oct 21, 2022
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.
Allow
reffields to include initializers withrefexpressions.Fixes #64720.
Fixes #64725.