D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6569 - Template fails to instantiate when alias this is used
Summary: Template fails to instantiate when alias this is used
Status: RESOLVED DUPLICATE of issue 2778
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 major
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2011-08-28 14:12 UTC by Andrej Mitrovic
Modified: 2011-10-23 22:46 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2011-08-28 14:12:01 UTC
enum Type
{
    A,
    B,
}

struct Foo {}
struct Bar
{
    Foo foo;
    alias foo this;
}

void main() 
{
    Bar bar;
    test!(Type.A)(bar);           // fail
    test!(Type.A)(cast(Foo)bar);  // ok
}

void test(Type type)(Foo foo)
    if (type == Type.A)
{
}

void test(Type type)(Foo foo)     // comment out and both run ok
    if (type == Type.B)
{
}

If you remove the second test() template both instantiations in main() will work, which is very odd.
Comment 1 Kenji Hara 2011-10-23 22:46:19 UTC

*** This issue has been marked as a duplicate of issue 2778 ***