Cannot take slice of scope static array in @safe code

Dennis dkorpel at gmail.com
Sun Feb 2 18:25:09 UTC 2020


Thanks for your response.

On Sunday, 2 February 2020 at 15:20:39 UTC, ag0aep6g wrote:
> Now it's important to realize that `scope` only applies to the 
> top-level of the type.

This is where my confusion was.
I knew scope wasn't transitive, so I thought that `scope 
string[1]` meant the static array could not escape the function, 
but the elements of it (the strings) could, since arr[0] would 
yield a `string` and not a `scope string`. I thought that it 
wouldn't have mattered if the element type had indirections 
(string) or not (int).

Now I realize scope applies to the elements, since indexing a 
static array doesn't actually remove a layer of indirection 
unlike a dynamic array.



More information about the Digitalmars-d-learn mailing list