[Issue 19442] New: Issues with multiple argument string mixin

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 28 17:04:24 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19442

          Issue ID: 19442
           Summary: Issues with multiple argument string mixin
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: nick at geany.org

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");

--


More information about the Digitalmars-d-bugs mailing list