www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19442] New: Issues with multiple argument string mixin


          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 puremagic.com
          Reporter: nick 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");

Nov 28 2018