[Issue 19650] New: static foreach eponymous template only has one implementation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Feb 5 18:45:09 UTC 2019


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

          Issue ID: 19650
           Summary: static foreach eponymous template only has one
                    implementation
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: atila.neves at gmail.com

This code:


------------------
import std.meta;

void main() {
    func!(double, int, double);
}

void func(A...)() {
    static foreach(Type; A) {{
        enum isType(T) = is(T == Type);
        alias filtered = Filter!(isType, A);
        pragma(msg, "Type: ", Type, " filtered: ", filtered);
    }}
}
------------------

Should print:

Type: double filtered: (double, double)
Type: int filtered: (int)
Type: double filtered: (double, double)


However, it prints this instead:

Type: double filtered: (double, double)
Type: int filtered: (double, double)
Type: double filtered: (double, double)


This is especially egregious since not using a double brace causes the compiler
to complain that `isType` has already been defined. The double braces make the
error go away but only the first implementation is used.

--


More information about the Digitalmars-d-bugs mailing list