[Dlang-internal] DIP1000 discussion and testing
Walter Bright via Dlang-internal
dlang-internal at puremagic.com
Tue Nov 22 19:25:20 PST 2016
On 11/20/2016 8:41 AM, Mathias Lang wrote:
> First I have a question: What is going to happen with `scope foo = new Object` ?
> Are we keeping it the way it currently is ?
Yes.
> 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.
I'll look into that.
> By the way, I reiterate my point that tying `scope` verification to `@safe`
> function is highly misleading and not necessary.
I understand your point. The trouble is, it will break too much code.
> 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;
> }
> ```
I get:
bug9.d(7): Error: cannot return non-void from void function
> 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'll have to investigate that one.
More information about the Dlang-internal
mailing list