Bug 19969 – Unhelpful error when attempting (incorrectly) to append to a string

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-06-15T18:24:22Z
Last change time
2019-12-22T06:51:15Z
Keywords
diagnostic, pull
Assigned to
No Owner
Creator
Peter Alexander

Comments

Comment #0 by peter.alexander.au — 2019-06-15T18:24:22Z
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.
Comment #1 by dlang-bot — 2019-06-15T22:17:55Z
@Basile-z created dlang/dmd pull request #10039 "fix issue 19969 - Unhelpful error when attempting (incorrectly) to append to a string" fixing this issue: - fix issue 19969 - Unhelpful error when attempting (incorrectly) to append to a string https://github.com/dlang/dmd/pull/10039
Comment #2 by dlang-bot — 2019-06-17T04:41:55Z
dlang/dmd pull request #10039 "fix issue 19969 - Unhelpful error when attempting (incorrectly) to append to a string" was merged into master: - b9d80468daebb9ba0b6bb8df0e3d78c03965dbb8 by Basile Burg: fix issue 19969 - Unhelpful error when attempting (incorrectly) to append to a string https://github.com/dlang/dmd/pull/10039