Bug 19442 – multiple argument string mixin dont support char literals
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-11-28T17:04:24Z
Last change time
2020-03-21T03:56:39Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
Nick Treleaven
Comments
Comment #0 by nick — 2018-11-28T17:04:24Z
Since dmd 2.083.0, Issue 19292, string mixins can accept multiple arguments. This sometimes does not work as expected. First, passing character literals gives a confusing error message:
enum x1 = 1;
pragma(msg, mixin('x',1)); // Error: incomplete mixin expression `'x'1`
pragma(msg, mixin("x",1)); // OK, outputs 1
Second, passing a template parameter list does not expand the arguments:
enum x1 = 1;
enum makeIdent(args...) = mixin(args);
pragma(msg, makeIdent!("x", 1)); // Error: undefined identifier `tuple`
// Using this works but only for two arguments
enum makeIdent(args...) = mixin(args[0], args[1]);
pragma(msg, makeIdent!("x", 1)); // Output: 1
Here's the real code I was working on (like compile-time std.conv.text but probably more efficient):
enum ctText(args...) = mixin("`", args, "`");
pragma(msg, ctText!(5, " bottles")); // Output: tuple(5, " bottles")
Above, args is not implicitly expanded.
// This works but only for two arguments
enum ctText(args...) = mixin("`", args[0], args[1], "`");
static assert(ctText!(5, " bottles") == "5 bottles");
Comment #1 by b2.temp — 2019-03-25T19:34:01Z
Can you open a separate issue for the second case please ?
Comment #2 by dlang-bot — 2019-03-25T20:20:00Z
@Basile-z created dlang/dmd pull request #9491 "fix issue 19442 - multiple argument string mixin dont support char literals" fixing this issue:
- fix issue 19442 - multiple argument string mixin dont support char literals
https://github.com/dlang/dmd/pull/9491