[Dlang-internal] DIP1000 discussion and testing

Mathias Lang via Dlang-internal dlang-internal at puremagic.com
Fri Dec 30 04:12:57 PST 2016


On Wednesday, 28 December 2016 at 01:25:22 UTC, Walter Bright 
wrote:
> On 12/27/2016 2:18 PM, Mathias Lang wrote:
>> Which brings me to the question, is `scope ref` supposed to 
>> apply to the `ref`
>> or to the type (i.e. `Foo` in this case) ?
>
> scope refers to the parameter's value, ref refers to the 
> parameter's address. The two are independent of each other.

Thanks (Y)

I just started testing methods, but didn't get far, because the 
following doesn't compile:
```
void getObj () @safe
{
     scope o = new Bar;
     auto p = o.foo;   // Line 9
}

class Bar
{
     Object foo () return scope @safe { return this; }
}

// scope1.d(9): Error: scope variable o assigned to non-scope 
parameter this calling scope1.Bar.foo
```

However making `foo` a function which accept a class works:
```
Object foo (return scope Object this_) @safe
{
     return this_;
}
```

Also, it looks like delegates to member functions are not marked 
scope where they should. The following compiles, but obviously 
should not since the context pointer of the delegate will be the 
instance `b`, which is on the stack.

```
void main () @safe
{
     fwd();
     auto x1 = Generator1();
     auto x2 = Generator2();
}

int delegate() @safe Generator1;
int delegate() @safe Generator2;

struct G1
{
     int generator () @safe { return 42; }
}

class G2
{
     int generator () @safe { return 42; }
}

void fwd () @safe @nogc
{
     G1 g1;
     scope g2 = new G2;
     Generator1 = &g1.generator;
     Generator2 = &g2.generator;
}
```


More information about the Dlang-internal mailing list