A file named `test_scope.d` containing @safe pure nothrow @nogc: struct S { @safe pure nothrow @nogc inout(int)[] opSlice() inout return scope { return x[]; } int[4] x; } int[] f() { S s; return s[]; } compiled with -dip1000 correctly errors as test_scope.d(16,13): Error: escaping reference to local variable s but if return type of `opSlice` is changed to `auto` the compiler acccepts it which is wrong.
This shrinks down a bit to: struct S { int[] // works //auto // doesn't work foo() return @safe { return x[]; } int[4] x; } @safe int[] f() { S s; return s.foo(); }
Note that it works if int[] is replaced by int*. https://github.com/dlang/dmd/pull/7076
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/fc9c84ba1722c02f0c1877ffa39134c84a5e13e0 fix Issue 17388 - [scope] e[] should be treated like &e as far as scope goes https://github.com/dlang/dmd/commit/09cd19d51b1e000dc81a61d167dc559480958f3e Merge pull request #7076 from WalterBright/fix17388 fix Issue 17388 - [scope] e[] should be treated like &e as far as sco… merged-on-behalf-of: Martin Nowak <code@dawg.eu>
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/fc9c84ba1722c02f0c1877ffa39134c84a5e13e0 fix Issue 17388 - [scope] e[] should be treated like &e as far as scope goes https://github.com/dlang/dmd/commit/09cd19d51b1e000dc81a61d167dc559480958f3e Merge pull request #7076 from WalterBright/fix17388