[Issue 12032] One case of refused slicing assignment to fixed size array

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 22 11:31:59 UTC 2022


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305 at gmail.com
         Resolution|---                         |INVALID

--- Comment #1 from RazvanN <razvan.nitu1305 at gmail.com> ---
This issue is invalid. The first case compiles because the compiler is able to
deduce that the returned array is of size 2 (the range bounds are literal and
therefore known at compile time). The second case is an assignment of slices,
therefore the error (if any) can only be caught at runtime. In the third case,
the length of the `a` array cannot be known because `a` is a dynamic array and
any number of elements could be added or deleted from a before we return the
slice. Therefore the compiler rejects it. If a would have been a static array,
then the compiler would have accepted the code because it can statically
determine that the returned array matches the expected size.

--


More information about the Digitalmars-d-bugs mailing list