On Thursday, 23 June 2022 at 16:08:01 UTC, Ola Fosheim Grøstad
wrote:
How am I supposed to write this:
```d
import std;
@safe:
struct node {
node* next;
}
auto connect(scope node* a, scope node* b)
{
a.next = b;
}
void main()
{
node x;
node y;
connect(&x,&y);
}
```
Error: scope variable `b` assigned to non-scope `(*a).next`
DMD accepts this:
```d
@safe:
struct node {
node* next;
}
void connect(ref scope node a, return scope node* b)
{
a.next = b;
}
void main()
{
node y;
scope node x;
connect(x, &y);
}
```
But that only works for this very special case. It falls apart
when you try to add a third node. As far as I understand, `scope`
cannot handle linked lists. A `scope` pointer cannot point to
another `scope` pointer.
So as to how you're supposed to do it: with @system.