[Issue 23297] New: 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 15:31:21 UTC 2022
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 at puremagic.com
Reporter: rubytheroobster at 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.
--
More information about the Digitalmars-d-bugs
mailing list