first draft Reducing the legal permutations of ref-return-scope

Walter Bright newshound2 at digitalmars.com
Tue May 13 18:57:21 UTC 2025


Good questions!

The idea is to eliminate ambiguity in the meaning, i.e. does a `return` apply to 
the `scope` or to the `ref`? The ambiguity happens when the `ref`, `return` and 
`scope` are all present. Is the `return` applying to the `ref`, or the `scope`?

The resolution is when there is a `return` and a `ref` present, it must be 
written as `return ref`. When there is a `return` and a `scope` present, it must 
be written as `return scope`. When there is a `return`, `scope`, and `ref` 
present, the `return` must immediately precede the `scope` or the `ref` it is 
meant to apply to.

There's a special case with the implicit `this` declaration:
```
struct S
{
      int* f() return; // doesn't comply with DIP text
}
```
is treated as if it were written:
```
struct S
{
      int* f(return ref S this);
}
```
The implicit `this` declaration is another source of confusion. I've been toying 
with the idea of allowing it to be part of the parameter list.


More information about the dip.development mailing list