www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23598] New: Another nasty forward reference bug

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

          Issue ID: 23598
           Summary: Another nasty forward reference bug
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: maxsamukha gmail.com

This one took me a long time to reduce. Marking it as a blocker, as I haven't
found an acceptable workaround yet.

----
alias aliases(a...) = a;

template sort(alias f, a...)
{
    static if (a.length > 0) // (1)
    {
        alias x = f!(a[1]);
        alias sort = a;
    }
    else
        alias sort = a;
}

alias SortedItems = sort!(isDependencyOf, Top, String); // (2)
pragma (msg, "1: ", SortedItems);

enum isDependencyOf(Item) = Item.DirectDependencies.length == 0;

struct Top
{
    alias DirectDependencies = aliases!();
}

struct String
{
    alias DirectDependencies = aliases!();

    pragma(msg, "2: ", SortedItems);
    enum l = SortedItems.length; // (3)
    static assert(is(typeof(SortedItems.length) == size_t)); // (4)
}
----
Error: no property `length` for `sort!(isDependencyOf, Top, String)` of type
`void`

The SortedItems tuple at (2) is (Top, String), which is correct, but at (3) it
is broken. However, at (4) it is correct again - the assert passes if (3) is
commented out. This may have something to do with the 'static if' at (1), as
the error goes away if the 'static if' and the 'else' branch are commented out.

--
Jan 04 2023