http://d.puremagic.com/issues/show_bug.cgi?id=3955
Summary: Very poor error message: accidentally assigning to
string literal in template
Product: D
Version: 1.056
Platform: All
OS/Version: All
Status: NEW
Keywords: diagnostic
Severity: normal
Priority: P2
Component: DMD
AssignedTo: [email protected]
ReportedBy: [email protected]
--- Comment #0 from Matti Niemenmaa <[email protected]>
2010-03-13 08:34:35 PST ---
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
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------