digitalmars.D.bugs - [Issue 23297] New: You Can Assign a dstring to a dchar[] if Both
- d-bugmail puremagic.com (39/39) Aug 18 2022 https://issues.dlang.org/show_bug.cgi?id=23297
https://issues.dlang.org/show_bug.cgi?id=23297 Issue ID: 23297 Summary: You Can Assign a dstring to a dchar[] if Both Sides of the Expression are Slices Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: rubytheroobster yandex.com The following code fails, like it should: ```d void main() { dchar[] a; //asset(typeof(a).stringof == "dchar[]") dstring b = "a"d; //assert(typeof(b).stringof == "immutable(dchar)[]"); a = b; //ERROR: VIOLATES THE TYPE SYSTEM } ``` However, the following code compiles and runs: ```d void main() { import std.stdio; dchar[] a = "ab".dup; writeln(typeof(a[0 .. $-1]).stringof); //Prints 'dchar[]' writeln(typeof(a[1 .. $]).stringof); //Prints 'immutable(dchar)[]' a[0 .. $-1] = a[1 .. $].idup; //Compiles, but WRONG --a.length; writeln(a); //Prints 'b' to stdout } ``` Given that the first example fails, the second example should also fail and output a similar error. --
Aug 18 2022