www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17576] New: mixin template cannot define alias

https://issues.dlang.org/show_bug.cgi?id=17576

          Issue ID: 17576
           Summary: mixin template cannot define alias
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: qs.il.paperinik gmail.com

mixin template Test(alias f)
{
    import std.traits : ReturnType;
    alias R = ReturnType!f;

    R foo() { }
}

struct S
{
    void foo(int) { }

    mixin Test!foo T;
    alias foo = T.foo;
}

gives me the error message "template instance std.traits.ReturnType!(foo) is
used as a type"

However, when R foo() { } is replaced with ReturnType!f foo() { } the error
message is "isCallable!(foo) is not an expression", and if one deletes the
alias for R, the error disappears.

Instead, if I precede the mixin template with "import std.traits : isCallable;"
and constrain it with "if (isCallable!f)", the error is "no property 'foo' for
type 'void'" essentially because it cannot instance isCallable!f for whatever
reason.

I suspect it is a bug in DMD. It could be in Phobos's ReturnType or isCallable.

--
Jun 29