[Issue 21137] Can't get the UDA given to the lambda expression parameters

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 10 11:28:56 UTC 2020


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

--- Comment #3 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
You're right, my mind was somewhere else when I did that. The problem is, D's
templates are complicated beasts (and untyped lambdas are templates), and the
information is undecidable in the general case:

    template foo(bool b, T) {
        static if (b) {
            void foo(@(T) T i) {}
        } else {
            enum T foo = T.init;
        }
    }

We don't know if the above even is a function, and even if we remove the bool
parameter, there's no possible type for the UDA on the parameter 'i' without an
explicit instantiation (and figuring out what template arguments are valid is
also a hard problem).

We could possibly expose a __traits that gives access to this information in
the limited cases where the template body has exactly one member which is a
function and whose parameters' UDAs can be determined.

IMO, this is material for a DIP on template introspection, possibly AST macros.

--


More information about the Digitalmars-d-bugs mailing list