Weird DIP1000 issue

tsbockman thomas.bockman at gmail.com
Thu Feb 9 01:08:35 UTC 2023


On Wednesday, 8 February 2023 at 23:03:17 UTC, Paul Backus wrote:
> On Wednesday, 8 February 2023 at 22:25:32 UTC, tsbockman wrote:
>> I think most of the confusion surrounding `scope` and related 
>> attributes stems from the fact that `scope` is transitive, 
>> when it really shouldn't be.
>
> This really is a good illustration of the confusion surrounding 
> `scope`, because `scope` is not transitive and never has been:
>
> ```d
> char* global;
>
> void main() @safe
> {
>     char* local;
>     scope char** p = &local;
>     global = *p; // ok
> }
> ```

Well then, I guess I don't understand the rules either.

In the [original 
sample](https://forum.dlang.org/post/zqvewsixzjvrothpqkzz@forum.dlang.org) the compiler insists that the value of `c` and `c.m` must be `scope` if `&vr` is, when it is only the next level of indirection up - the memory storing that value - that is actually on the stack within `vr`.

Aggregates sometimes behave in ways that at least resemble 
`scope` transitivity, even if it's not really the same thing:

```D
struct S {
     int* i;
     int* j;
}

int* escape;
int x, y;

void main() @safe
{
     int z;

     S a;
     a.i = &x;
     a.j = &y;
     escape = a.i; // Allowed

     S b;
     b.i = &y;
     b.j = &z;
     escape = b.i; // Rejected because b.j needs scope, which 
apparently forces b and all its fields to be scope, too.
}
```



More information about the Digitalmars-d mailing list