[Issue 9235] New: Template mixin makes doesn't allow to mixin in non-conflicting overloads

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 28 04:55:50 PST 2012


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

           Summary: Template mixin makes doesn't allow to mixin in
                    non-conflicting overloads
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: dmitry.olsh at gmail.com


--- Comment #0 from Dmitry Olshansky <dmitry.olsh at gmail.com> 2012-12-28 04:55:48 PST ---
The program below show the problem. If it was by design then design is faulty
as the broken error message indicates.

(I have a real-world use case for this and see no reason to forbid it)

enum Command{
    Char,
    Any,
    Fork,
    Jump,
    End
};

template FlowEvaluator()
{
    //if control flow
    bool execute(Command cmd)()
        if(cmd == Command.Jump || cmd == Command.Fork)
    {
        return false;
    }
}

template MatchEvaluator()
{
    //if operation
    bool execute(Command cmd)()
        if(cmd == Command.Char || cmd == Command.Any || cmd == Command.End) 
    {
        return false;
    }
}

struct Machine
{
    mixin FlowEvaluator;
    mixin MatchEvaluator;

    bool exec()
    {
        return execute!(Command.Any)();
    }
}

Fails with:
mixin.d(36): Error: template instance execute!(cast(Command)1) ambiguous
template declaration 
mixin.Machine.MatchEvaluator!().execute(Command cmd)() if (cmd == Command.Char
|| cmd == Command.Any || cmd == Command.End)
and
mixin.Machine.FlowEvaluator!().execute(Command cmd)() if (cmd == Command.Jump
|| cmd == Command.Fork)

mixin.d(36): Error: template instance execute!(cast(Command)1)
execute!(cast(Command)1) does not match template declaration execute(Command
cmd)() if (cmd == Command.Jump || cmd == Command.Fork)

mixin.d(36): Error: function expected before (), not execute!(cast(Command)1)
of type void

The second message hints to me that compiler in fact knows perfectly well which
one template does match the instantiation but something prevented it from just
picking it.

Tested on 2.061alpha, I think it was there all along.
Marking as major as there is either bogus diagnostic or a broken feature.

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


More information about the Digitalmars-d-bugs mailing list