D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6457 - [CTFE] .idup or casting of char[] does not really create a string literal recognizable in 'mixin', which causes a line-less error
Summary: [CTFE] .idup or casting of char[] does not really create a string literal rec...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 critical
Assignee: No Owner
URL:
Keywords: diagnostic, rejects-valid
Depends on:
Blocks: 5373
  Show dependency treegraph
 
Reported: 2011-08-08 14:11 UTC by kennytm
Modified: 2011-08-14 13:23 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description kennytm 2011-08-08 14:11:52 UTC
Test case:

-----------------------------
string bug6457() {
    auto d = new char[6];
    d[] = "int a;";
    return d.idup;           // <-- won't make a real string
    // return cast(string)d; // <-- neither does this
}
mixin(bug6457());
-----------------------------
Error: argument to mixin must be a string, not (['i','n','t',' ','a',';'])
-----------------------------

This affects all codes that uses std.array.appender. 'mixin' should be able to accept a string casted/idup-ed from a 'char[]', or the interpreter should be able to convert a 'char[]' expression to a StringExp in a 'cast(string)', and no matter which solution is taken, the error of 'mixin' should have the line number.
Comment 1 Trass3r 2011-08-08 16:24:43 UTC
Isn't this even a regression?
Comment 2 Don 2011-08-08 21:29:39 UTC
This doesn't work either, and it doesn't involve CTFE:

const char[] s = ['i','n','t',' ','a',';'];
mixin(s);
It's one of the few cases where arrays literals of chars aren't being accepted as string literals.
Comment 3 Don 2011-08-10 02:56:20 UTC
This particular test case is fixed in this commit:

https://github.com/D-Programming-Language/dmd/commit/df2b9cdff0f5c23449be7a6b9a875bcf92b38f8d

I created bug 6462 for the test case in comment 2, which has does not involve CTFE.
Comment 4 Trass3r 2011-08-14 13:23:07 UTC
Another test case which still triggers that error is bug 5373.