[Issue 23297] You Can Assign a dstring to a dchar[] if Both Sides of the Expression are Slices
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Aug 18 16:48:52 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23297
Ruby The Roobster <rubytheroobster at yandex.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|dlang.org |dmd
Severity|enhancement |normal
--- Comment #3 from Ruby The Roobster <rubytheroobster at 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.
--
More information about the Digitalmars-d-bugs
mailing list