[Dlang-internal] DIP1000 discussion and testing
Mathias Lang via Dlang-internal
dlang-internal at puremagic.com
Sun Nov 20 08:41:36 PST 2016
Now that we have https://github.com/dlang/dmd/pull/6253 I came
back to test it a bit.
First I have a question: What is going to happen with `scope foo
= new Object` ?
Are we keeping it the way it currently is ? It's something we
highly rely on at work and it looks like it could work nicely
with the enhancements, but it wasn't mentioned anywhere.
And from a quick test (Using `-dip25 -transition=safe` and
5928249 which is the commit of this P.R.), the following code:
```
void main () @safe
{
scope o = new Object();
}
```
Results in the following error:
scope2.d(3): Error: delete o is not @safe but is used in @safe
function main
Which works with the compiler I'm currently using, 2.071.2.
By the way, I reiterate my point that tying `scope` verification
to `@safe` function is highly misleading and not necessary. I
originally crafted a couple of test case, and when everything
worked, I was left puzzled for a minute before realizing I forgot
`@safe`.
Second point, on testing your P.R., I found that the following
code compiles:
```
alias FunDG = void delegate () @safe;
void main () @safe
{
int x = 42;
scope FunDG f = () { assert(x == 42); };
return fun(&f);
}
FunDG fun (scope FunDG* ptr) @safe
{
return *ptr;
}
```
As well as the following:
```
alias FunDG = void* delegate () @safe;
void main () @safe
{
void* x = fwd();
}
void* fwd () @safe
{
int x = 42;
scope FunDG f = () { return &x; };
return fun(f);
}
void* fun (scope FunDG ptr) @safe
{
return ptr();
}
```
I'm not quite sure how one would express taking a pointer to a
scope value though.
More information about the Dlang-internal
mailing list