[Issue 23300] std.array : array wrongly propagates scopeness of source

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Aug 24 12:36:40 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23300

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305 at gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305 at gmail.com> ---
(In reply to Ate Eskola from comment #0)
> This should compile but does not on dmd 2.100, using -preview=dip1000 flag.
> 
> -------------
> @safe int[] fun()
> { import std : array, map;
>   scope r = [1,2,3].map!"a+3";
>   return r.array;
> }
> -------------
> 
> Were I returning `r` directly, this would be escaping a reference to scoped
> data, but `array` copies the data. Returning `array`ed range should be
> allowed, `scope` or no.

The problem here is that `r` is `scope` so for it to be able to be passed to
`array`, `array` also needs to receive a scope parameter. However, `array`'s
parameter cannot be `scope` because it is copied into allocated memory.

By the current scope rules this seems to be correct behavior, making this bug
report invalid.

--


More information about the Digitalmars-d-bugs mailing list