assert(false, strVar) has to be used to output a string variable in CTFE. At the moment there is no other possibility as pragma(msg, ...) and writeln is not working.
Also with the new CTFE it isn't 100% clear whether ctfeWriteln will come:
http://forum.dlang.org/post/[email protected]
For this example
string test(string s)
{
string tmp = s;
tmp = tmp[4..$];
assert(false, tmp);
return tmp;
}
enum foo =
`1234
5678
`;
void main()
{
enum bar = test(foo);
}
The output is (dmd 2.075.0-b2):
C:\Users\user\Desktop>rdmd app
app.d(6): Error: "1234\x0a5678\x0a"[4..10]
app.d(17): called from here: test("1234\x0a5678\x0a")
Failed: ["dmd", "-v", "-o-", "app.d", "-I."]
Instead of the content of tmp, the full content is shown with the slice information [4..10].
This output is in a real scenario quite irritating as the string is much longer and a lot more logic is going on and also the string isn't passed back but a structure. I already thought dmd isn't working at all, as the tmp variable didn't changed its value. Only after having 5 looks at the minimal example output, I saw the slice information.
Comment #1 by robert.schadek — 2024-12-13T18:53:14Z