Bug 20868 and dip1000
Meta
jared771 at gmail.com
Mon Jan 11 15:19:07 UTC 2021
On Monday, 11 January 2021 at 13:20:12 UTC, RazvanN wrote:
> Hello everyone,
>
> Bug 20868 [3] reports the following code:
>
> void scoped (scope void delegate() dg)
> {
> static void delegate()[] dgs;
> // dgs ~= dg; // error
>
> nonScoped(dg); // not an error???
> }
>
> void nonScoped (void delegate() dg)
> {
> static void delegate()[] dgs;
> dgs ~= dg;
> }
>
> void main ()
> {
> int x;
> scoped({x = 100;});
> }
>
> The above code, compiled with -dip1000, compiles succesfully.
>
> If the scoped and nonScoped functions are annotated with @safe,
> the nonScoped call will be reported as an error (as it should).
>
> Spec [1] says: "scope escape analysis is only done for @safe
> functions. For other functions scope semantics must be manually
> enforced.". Dip1000 [2] says: "Errors for scope violations are
> only reported in @safe code.".
>
> My understanding is that scope checks are performed only when
> dip1000 is enabled and in @safe code. However, that is not
> entirely the case. For example:
>
> int* scoped(scope int* p) {
> return p;
> }
>
> void main() {
> int i;
> int* p = &i;
> scoped(p);
> }
>
> Compiled with dip1000, yields: "onlineapp.d(2): Error: scope
> variable `p` may not be returned".
>
> I want to fix the issue, but I don't know what the official
> specification is. Should we disable any dip1000 checks in
> @system functions or is there any other piece of spec that I am
> missing?
>
> Cheers,
> RazvanN
>
> [1] https://dlang.org/spec/function.html#scope-parameters
> [2]
> https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md
> [3] https://issues.dlang.org/show_bug.cgi?id=20868
I've run into a similar problem. I never got a satisfactory
answer from Walter, and the only solution I could come up with
other than rewriting the code was to reach for @trusted.
More information about the Digitalmars-d
mailing list