D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7552 - Cannot get and combine a part of overloaded functions
Summary: Cannot get and combine a part of overloaded functions
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2012-02-20 04:47 UTC by Kenji Hara
Modified: 2012-02-20 16:19 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 Kenji Hara 2012-02-20 04:47:55 UTC
Extracting a function symbol from overloads by __traits(getOverloads), and combining them by alias declaration should generate new overloads. See following code.

----
template TypeTuple(T...){ alias T TypeTuple; }
template Id(      T){ alias T Id; }
template Id(alias A){ alias A Id; }

struct S
{
    static void foo(){}
    static void foo(int){}
}

struct T
{
    alias TypeTuple!(__traits(getOverloads, S, "foo")) FooInS;
    alias FooInS[0] foo;    // should be S.foo()
    static void foo(string){}
}

struct U
{
    alias TypeTuple!(__traits(getOverloads, S, "foo")) FooInS;
    alias FooInS[1] foo;    // should be S.foo(int)
    static void foo(string){}
}

void main()
{
    alias TypeTuple!(__traits(getOverloads, S, "foo")) FooInS;
    static assert(FooInS.length == 2);
                                      FooInS[0]();
    static assert(!__traits(compiles, FooInS[0](0)));
    static assert(!__traits(compiles, FooInS[1]()));
                                      FooInS[1](0);

                                      Id!(FooInS[0])();
    static assert(!__traits(compiles, Id!(FooInS[0])(0)));
    static assert(!__traits(compiles, Id!(FooInS[1])()));
                                      Id!(FooInS[1])(0);

    alias TypeTuple!(__traits(getOverloads, T, "foo")) FooInT;
    static assert(FooInT.length == 2);                  // fail
                                      FooInT[0]();
    static assert(!__traits(compiles, FooInT[0](0)));
    static assert(!__traits(compiles, FooInT[0]("")));
    static assert(!__traits(compiles, FooInT[1]()));
    static assert(!__traits(compiles, FooInT[1](0)));   // fail
                                      FooInT[1]("");    // fail

    alias TypeTuple!(__traits(getOverloads, U, "foo")) FooInU;
    static assert(FooInU.length == 2);
    static assert(!__traits(compiles, FooInU[0]()));
                                      FooInU[0](0);
    static assert(!__traits(compiles, FooInU[0]("")));
    static assert(!__traits(compiles, FooInU[1]()));
    static assert(!__traits(compiles, FooInU[1](0)));
                                      FooInU[1]("");
}
----
Comment 2 github-bugzilla 2012-02-20 15:15:51 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/2d23bfa74395340adf720c406678604b9704915d
Merge pull request #748 from 9rnsr/fix7552

Issue 7552 - Cannot get and combine a part of overloaded functions