www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22696] New: getSymbolsByUDA can't be used in static foreach

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

          Issue ID: 22696
           Summary: getSymbolsByUDA can't be used in static foreach over
                    parent type
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: jack jackstouffer.com

Here is a simplified version of real code I tried to write using
getSymbolsByUDA:

    import std.traits;

    enum Runnable;

    struct SubSystem
    {
        void run();
    }

    struct Manager
    {
         Runnable SubSystem subsystem;

        void run()
        {
            static foreach(system; getSymbolsByUDA!(Manager, Runnable))
            {
                system.run();
            }
        }
    }

    void main()
    {
        Manager m;
        m.run();
    }

Result:

    onlineapp.d(16): Error: value of `this` is not known at compile time

This seems to be the most logical and straight-forward way to write this code.
Whether it's due to a bug in the getSymbolsByUDA implementation, a bug in DMD,
or a limitation in the language, it's my personal opinion this code should
compile and "just work".

At the VERY LEAST the error message should be more helpful to the user on how
to get the desired functionality.

--
Jan 21 2022