[Issue 19969] New: Unhelpful error when attempting (incorrectly) to append to a string

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jun 15 18:24:22 UTC 2019


          Issue ID: 19969
           Summary: Unhelpful error when attempting (incorrectly) to
                    append to a string
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: peter.alexander.au at gmail.com

void main() {
  string s;
  s += "foo"; // Error: slice s is not mutable

Of course, the user meant to use ~=, but many other languages use += so this
will be a common occurrence. An error is expected here, but erroring on
mutability is unhelpful. It's also incorrect since the slice *is* mutable (even
though the elements are not).

Note, with a mutable string, you get a more helpful error:

void main() {
  char[] s;
  s += "foo"; // Error: invalid array operation s += "foo" (possible missing

The enhancement request here is for a better error. Preferably something
mentioning that the operation is invalid.


More information about the Digitalmars-d-bugs mailing list