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 () {}
}
Comment #1 by feco.graczer — 2020-11-12T09:57:17Z
DMD64 D Compiler v2.094.0
Comment #2 by feco.graczer — 2020-11-12T11:19:33Z
sorry, compiler was DMD v2.093.1 (with ldc2)
Comment #3 by robert.schadek — 2024-12-13T19:12:39Z