www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21379] New: UDA's implemented with functions and taking alias

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

          Issue ID: 21379
           Summary: UDA's implemented with functions and taking alias
                    params don't compile
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: feco.graczer gmail.com

public struct TestX(alias ST)
{
    alias serializer = ST;
}

TestX!ST resultSerializer (alias ST) ()
{
        return TestX!ST();
}

// this compiles, no problem
 resultSerializer!(function (string){return "hello";})() 
void f () {}

class X
{
        // this one doesn't compile
         resultSerializer!(function (string){return "hello";})()
        void f () {}
}

compiler error message for the UDA of X.f:

function tests.X.resultSerializer!(function (string)
{
return "hello";
}
).resultSerializer need this to access member resultSerializer

The workaround was to not use functions to implement UDA, but to create a class
to implement it:

public struct ResultSerializer(alias ST)
{
    alias serializer = ST;
}

 ResultSerializer!(function (string){return "hello";})()
void f () {}

class X
{
         ResultSerializer!(function (string){return "hello";})()
        void f () {}
}

--
Nov 12 2020