www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1451] New: overloading methods by mixin in static if doesn't work

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1451

           Summary: overloading methods by mixin in static if doesn't work
           Product: D
           Version: 1.020
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: leo.dahlmann gmail.com


<code>
template Foo(T)
{
    void callme(T)
    {

    }
}

class Bar
{
    mixin Foo!(int) F1;
    alias F1.callme callme;

    static if(true)
    {
        mixin Foo!(float) F2;
        alias F2.callme callme;
    }
}

void main()
{
    Bar bar = new Bar;
    bar.callme(cast(int)0); // <- works
    bar.callme(cast(float)0); // <- fails (line 25)
}
</code>

This code fails to compile with these error messages:
test.d(25): function test.Bar.Foo!(int).callme ((int _param_0)) does not match
parameter types (float)
test.d(25): Error: cannot implicitly convert expression (0) of type float to
int

After commenting out the static if it compiles perfectly, like expected.


-- 
Aug 29 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1451


Alexandre Fournier <af liquidstate.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |af liquidstate.eu
            Version|1.020                       |1.057
         OS/Version|Windows                     |Linux



PDT ---
<code>
struct A
{
        static A opCall()
        {
                A ret;
                return ret;
        }

        mixin M;
}

template M()
{
        static typeof(*this) opCall(uint i)
        {
                A ret;
                return ret;
        }
}

int main(char[][] args)
{
        A a1 = A();
        A a2 = A(42);
        return 0;
}
</code>

Line 24: function t.A.opCall () does not match parameter types (int)
Line 24: Error: expected 0 arguments, not 1

Still the same bug, simple test case above

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 22 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1451


dawg dawgfoto.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dawg dawgfoto.de



cat > bug.d << CODE
mixin template func(T)
{
    void bar(T) {}
}

mixin func!(int);
mixin func!(double);

void baz()
{
    bar(0);
    bar(1.0);
}
CODE

dmd -c bug

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 05 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1451


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |timon.gehr gmx.ch
         Resolution|                            |WORKSFORME



The errors in the two comments are by design.


the surrounding scope.


prevent accidental function hijacking.

The original bug report is valid, and the example code now compiles with DMD
2.058.

If anyone disagrees, please reopen.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 05 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1451





prevent accidental function hijacking. Makes sense. Just for the record, I tried to unroll a TypeTuple into an overloadset, which now works fine after merging the overloads. mixin template _visit(Nodes...) if(Nodes.length) { void visit(Nodes[0] n); static if (Nodes.length > 1) { mixin _visit!(Nodes[1 .. $]) vi; alias vi.visit visit; } } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 06 2012