D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19650 - static foreach eponymous template only has one implementation
Summary: static foreach eponymous template only has one implementation
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-05 18:45 UTC by Atila Neves
Modified: 2021-04-04 19:13 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Atila Neves 2019-02-05 18:45:09 UTC
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.
Comment 1 moonlightsentinel 2021-04-04 19:13:48 UTC
Current master prints:

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