Bug 3955 – Very poor error message: accidentally assigning to string literal in template

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2010-03-13T08:34:00Z
Last change time
2014-02-15T02:28:34Z
Keywords
diagnostic
Assigned to
nobody
Creator
matti.niemenmaa+dbugzilla

Comments

Comment #0 by matti.niemenmaa+dbugzilla — 2010-03-13T08:34:35Z
For the following code: template T(char[] s) { static if (s[0] = 'f') // error here; line 2 const T = ""; else const T = "" ~ T!(s); } const char[] A = T!("foo"); // line 8 const char[] B = "" ~ A; DMD 1.056 emits: $ dmd -c arst.d arst.d(8): Error: cannot implicitly convert expression (__error ~ __error) of type int to char[] Which is about as obtuse as possible: - __error looks like something that should only show up when debugging the compiler. It's certainly not to be found anywhere in the source. - There is no ~ on line 8: the message points only to the use of T, not the actual problem which is within T. - DMD's usual habit of using "int" when it hits any kind of error. Removing the apparently unrelated constant B from line 9, we get the following message that actually indicates the problem. This is what I'd expect to get regardless of B: $ dmd -c arst.d arst.d(2): Error: string literals are immutable arst.d(2): Error: expression 'f' = 'f' is not constant or does not evaluate to a bool
Comment #1 by clugdbug — 2011-02-12T14:47:06Z
Fixed DMD 1.061.