[Dlang-internal] DIP1000 discussion and testing

Walter Bright via Dlang-internal dlang-internal at puremagic.com
Sat Oct 22 19:34:00 PDT 2016


On 10/22/2016 8:52 AM, Mathias Lang wrote:
> I was looking at the DIP, and checked out the P.R. branch to test it, and I
> cannot see how it could work if `scope` is not transitive.
> It is just pushing the problem one level down.
>
> For example:
>
> ```
> alias FunDG = void delegate () @safe;
>
> struct Escaper
> {
>     FunDG DG;
> }
>
> FunDG escapeDg1 (scope FunDG d) @safe
> {
>     Escaper e;
>     e.DG = d;
>     return e.DG;
> }
> ```
>
> This compiles, and escapes a `scope delegate`.

1. It is not an example of transitivity. e and d are at the same level, being a 
field does not make it a level down.

2. You're right that the above should error, I'll look into it.


> Finally, I agree with Dicebot that having scope infered when the type is
> specified is extremely confusing,

What is confusing about it?

    scope int* p = ...;
    int* q = p; // q becomes 'scope' as well

The compiler already does tons of inference for types and attributes. People 
should be well used to it by now :-)


> and makes writing test cases, and code in
> general, much more complicated.

Actually, it makes things much simpler allowing the compiler to take care of it. 
The whole scope thing would be fairly unusable if one had to manually add all 
the annotations.



More information about the Dlang-internal mailing list