www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Scope checking on static array struct doesn't kick in

reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
I've tagged the ref-returning functions (in this case `opSlice`) 
with `return scope` for my statically allocated array struct at

https://github.com/nordlow/phobos-next/blob/master/src/arrayn.d

but for some reason the scope-checking (via -dip1000) allows both

https://github.com/nordlow/phobos-next/blob/bde41f92b5373dd1365ad19ef9d0ecee4eb2d2cd/src/arrayn.d#L350

and

https://github.com/nordlow/phobos-next/blob/bde41f92b5373dd1365ad19ef9d0ecee4eb2d2cd/src/arrayn.d#L390

to compile eventhough the life-time of the slices clearly 
outlives (is defined prior to) the lifetime of the fixed-length 
(stack-allocated) array/string struct instance.

Have I missed something or is this simply not yet supported?
May 09 2017
parent reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Tuesday, 9 May 2017 at 11:52:35 UTC, Nordlöw wrote:
 I've tagged the ref-returning functions (in this case 
 `opSlice`) with `return scope` for my statically allocated 
 array struct at
Here's a simpler example https://github.com/nordlow/phobos-next/blob/cf85f449d24981fbe6269f8096db23282e2fbb65/tests/test_scope.d
May 09 2017
next sibling parent Stanislav Blinov <stanislav.blinov gmail.com> writes:
On Tuesday, 9 May 2017 at 12:25:29 UTC, Nordlöw wrote:
 On Tuesday, 9 May 2017 at 11:52:35 UTC, Nordlöw wrote:
 I've tagged the ref-returning functions (in this case 
 `opSlice`) with `return scope` for my statically allocated 
 array struct at
Here's a simpler example https://github.com/nordlow/phobos-next/blob/cf85f449d24981fbe6269f8096db23282e2fbb65/tests/test_scope.d
Looks like a bug, if you change "auto" to "int[]" it starts complaining in f(). I have a question though, why is the syntax like this:
 auto opSlice() return scope;
? I don't see such in the DIP, proposed there is simply "scope" to the left of the declaration, i.e.
 scope auto opSlice();
Although with that syntax dmd complains about escaping 'this', as if it was scope { auto opSlice(); }. Is 'return scope' the syntax that is supposed to be used and it's just not reflected in the DIP, or?..
May 09 2017
prev sibling parent reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Tuesday, 9 May 2017 at 12:25:29 UTC, Nordlöw wrote:
 On Tuesday, 9 May 2017 at 11:52:35 UTC, Nordlöw wrote:
 I've tagged the ref-returning functions (in this case 
 `opSlice`) with `return scope` for my statically allocated 
 array struct at
Here's a simpler example https://github.com/nordlow/phobos-next/blob/cf85f449d24981fbe6269f8096db23282e2fbb65/tests/test_scope.d
If I change the return value of `S.opSlice` to `int[]` correct `scope`-error handling kicks in. Tha is, scope checking via -dip1000 works for struct S { safe pure nothrow nogc int[] opSlice() return scope { return x[]; } int[4] x; } but not for struct S { safe pure nothrow nogc auto opSlice() return scope { return x[]; } int[4] x; } . I'll write a Bugzilla issue later today.
May 09 2017
parent =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Tuesday, 9 May 2017 at 13:30:49 UTC, Nordlöw wrote:
 I'll write a Bugzilla issue later today.
https://issues.dlang.org/show_bug.cgi?id=17388
May 09 2017