http://d.puremagic.com/issues/show_bug.cgi?id=7535

           Summary: Position of method in code inside class/struct decides
                    that code is proper or invalid
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: nazriel6...@gmail.com


--- Comment #0 from Damian Ziemba <nazriel6...@gmail.com> 2012-02-17 20:42:09 
PST ---
Greetings.

I've faced strange behaviour while working on my project.


// First snipped
//---
struct IrcEvent(T)
{
    private T[] _container;

    bool opOpAssign(string op, R)(R dlg)
    if (op == "+")
    {
        _container ~= dlg;

        return true;
    }
}

class IrcClient
{
    public IrcEvent!(void delegate(string)) OnMessageReceived;
}


class Foo
{
    static public void Dispatch(IrcClient session)
    {
        auto operator = new Foo;
        session.OnMessageReceived += &operator.Dispatch;
    }

    public void Dispatch(string msg)
    {
    }
}

void main()
{
    auto irc = new IrcClient;
    Foo.Dispatch(irc);
}
//---

Compiler refuse to compile this code with such message:

//---
./test.d(10): Error: cannot append type void delegate(IrcClient session) to
type void delegate(string)[]
./test.d(27): Error: template instance test.IrcEvent!(void
delegate(string)).IrcEvent.opOpAssign!("+",void delegate(IrcClient session))
error instantiating
//---

But when I change position of Dispatch methods in Foo class...

//Second source
//---
struct IrcEvent(T)
{
    private T[] _container;

    bool opOpAssign(string op, R)(R dlg)
    if (op == "+")
    {
        _container ~= dlg;

        return true;
    }
}

class IrcClient
{
    public IrcEvent!(void delegate(string)) OnMessageReceived;
}


class Foo
{
    public void Dispatch(string msg)
    {
    }

    static public void Dispatch(IrcClient session)
    {
        auto operator = new Foo;
        session.OnMessageReceived += &operator.Dispatch;
    }
}

void main()
{
    auto irc = new IrcClient;
    Foo.Dispatch(irc);
}
//---

Compiler doesn't complain!
The only difference between those 2 code snippets is position of Dispatch
method. 
In first code example non-static version of method is under static version and
in second example static version of method is under non-static version.

In my opinion this is a bug, compiler should look at methods definitions and
try to fit delegate not fail on first attempt.


Best regards,
Damian Ziemba

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to