Thread overview
[Issue 23297] You Can Assign a dstring to a dchar[] if Both Sides of the Expression are Slices
Aug 18, 2022
anonymous4
Aug 18, 2022
anonymous4
Aug 18, 2022
Ruby The Roobster
Aug 18, 2022
kinke
Aug 18, 2022
Ruby The Roobster
August 18, 2022
https://issues.dlang.org/show_bug.cgi?id=23297

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from anonymous4 <dfj1esp02@sneakemail.com> ---
The second example should work, it's array copy - copies elements from one array to another. The first example is slice assignment that would refer to the same array.

--
August 18, 2022
https://issues.dlang.org/show_bug.cgi?id=23297

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
          Component|dmd                         |dlang.org
         Resolution|INVALID                     |---
           Severity|normal                      |enhancement

--- Comment #2 from anonymous4 <dfj1esp02@sneakemail.com> ---
I guess, documentation can be improved here, it mentions only array copy for static array and not for slices.

--
August 18, 2022
https://issues.dlang.org/show_bug.cgi?id=23297

Ruby The Roobster <rubytheroobster@yandex.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|dlang.org                   |dmd
           Severity|enhancement                 |normal

--- Comment #3 from Ruby The Roobster <rubytheroobster@yandex.com> ---
(In reply to anonymous4 from comment #1)
> The second example should work, it's array copy - copies elements from one array to another. The first example is slice assignment that would refer to the same array.

Can you be more clear?  I think you got the two examples mixed up.

Also, the second example compiles with wchar and char, not just dchar, and the following works:

```d
void main()
{
    wchar[] a = "ab"w.dup;
    wchar[]b = a.dup;
    import std.stdio;
    writeln("Type of a[0 .. $-1]: ", typeof(a[0 .. $-1]).stringof);
    writeln("Type of b[1 .. $].idup: ", typeof(b[1 .. $].idup).stringof);
    a[0 .. $-1] = b[1 .. $].idup; //See?  Two completely different arrays.
    --a.length;
    writeln(a);
    writeln(typeof(a).stringof);
}
```

This is assigning an array of immutable wchars to an array of mutable wchars. No matter how you put it, this is a violation of the type system.

--
August 18, 2022
https://issues.dlang.org/show_bug.cgi?id=23297

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
                 CC|                            |kinke@gmx.net
         Resolution|---                         |INVALID

--- Comment #4 from kinke <kinke@gmx.net> ---
(In reply to anonymous4 from comment #2)
> I guess, documentation can be improved here, it mentions only array copy for static array and not for slices.

IMO fine: https://dlang.org/spec/arrays.html#array-copying

--
August 18, 2022
https://issues.dlang.org/show_bug.cgi?id=23297

--- Comment #5 from Ruby The Roobster <rubytheroobster@yandex.com> ---
(In reply to kinke from comment #4)
> (In reply to anonymous4 from comment #2)
> > I guess, documentation can be improved here, it mentions only array copy for static array and not for slices.
> 
> IMO fine: https://dlang.org/spec/arrays.html#array-copying

Okay.  Now I see why this isn't a bug.

--