The span safety rules at https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/span-safety.md describe rules that would make it safe to reassign ref locals (and ref parameters), presumably with some syntax similar to variable = ref somelvalue. I propose we add support for this.
As part of this, we'd also allow iteration variables to be ref in for and foreach loops (as initially tracked by #1046).
LDM
https://github.com/dotnet/csharplang/blob/master/meetings/2017/LDM-2017-10-02.md
This was discussed in the 2017-09-02 LDM meeting, with the following tentative directions:
- We will try to get ref reassignment into release 7.2 (update: we didn't manage to get this into 7.2, so it is now a 7.3 candidate)
- The syntax for ref reassignment is
e1 = ref e2. In other words, there is a single ref keyword and it appears after the = operator.
- This is an expression form. It yields an lvalue.
- Ref parameters may be ref-reassigned.
We do not expect to support "uninitialized" ref variables at this time. That is a possible future direction. We think it is a straightforward and simple extension, and we anticipate doing it sooner rather than later. If it turns out to be easy, it is possible it would make 7.2.
This was further discussed in the 2017-10-25 LDM meeting, where it was requested that the following be added to the scope of this championed issue for tentative work in C# 7.3:
The span safety rules at https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/span-safety.md describe rules that would make it safe to reassign ref locals (and ref parameters), presumably with some syntax similar to
variable = ref somelvalue. I propose we add support for this.As part of this, we'd also allow iteration variables to be
refinforandforeachloops (as initially tracked by #1046).LDM
https://github.com/dotnet/csharplang/blob/master/meetings/2017/LDM-2017-10-02.md
This was discussed in the 2017-09-02 LDM meeting, with the following tentative directions:
e1 = ref e2. In other words, there is a singlerefkeyword and it appears after the=operator.We do not expect to support "uninitialized" ref variables at this time. That is a possible future direction. We think it is a straightforward and simple extension, and we anticipate doing it sooner rather than later. If it turns out to be easy, it is possible it would make 7.2.
This was further discussed in the 2017-10-25 LDM meeting, where it was requested that the following be added to the scope of this championed issue for tentative work in C# 7.3:
refinforandforeachloops #1046) declaringforandforeachiteration variables asref, giving them some appropriate semantics.