https://issues.dlang.org/show_bug.cgi?id=22539
--- Comment #10 from Walter Bright <[email protected]> --- Moving on from my previous mistakes: @safe: ref int* identity(ref return scope int* x) { return x; } int* escape() { int stackVar; scope int* x = &stackVar; int* y = identity(x); return y; // error: scope variable `y` may not be returned } Good. Next, @safe: ref int*[1] identity(ref return scope int*[1] x) { return x; } int*[1] escape() { int stackVar; scope int*[1] x = [&stackVar]; int*[1] y = identity(x); return y; // error: scope variable `y` may not be returned } Good. int* escape() { int stackVar; scope int*[1] x = [&stackVar]; int*[1] y = identity(x); return y[0]; // error: scope variable `y` may not be returned } Good. int* escape() { int stackVar; scope int*[1] x = [&stackVar]; int*[1] y = identity(x); int*[] z = y[]; // error: cannot take address of `scope` local `y` return z[0]; } Good. Here, the slicing of `y` is properly detected. But if we put the [] after the identity call: int* escape() { int stackVar; scope int*[1] x = [&stackVar]; int*[] y = identity(x)[]; return y[0]; } No error; bad. The slicing of the return value of identity() is not properly propagating the scope-ness of its argument x. This would be a problem in escape.d. --
