dotnet / dotnet/csharplang

Champion: ref local reassignment (15.7)

Open
#933 21 comments 18 reactions 1 assignee Claimed by @gafter View on GitHub
Implemented Needs ECMA Spec Proposal Proposal champion
Dominant language
C#
Stars
12.7k
Forks
1.1k
Avg merge
11h 1m
Merged PRs (30d)
3

Description

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 https://github.com/dotnet/csharplang/issues/1046).

- [x] Proposal added (https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/ref-local-reassignment.md)
- [x] Discussed in LDM (2017-10-02)
- [ ] Decision in LDM
- [ ] Finalized (done, rejected, inactive)
- [ ] Spec'ed

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:
- Add support for declaring uninitialized ref locals, which includes defining their escape scope and some appropriate definite assignment treatment.
- Add support for (#1046) declaring `for` and `foreach` iteration variables as `ref`, giving them some appropriate semantics.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.