January 10, 2022
https://issues.dlang.org/show_bug.cgi?id=22662

          Issue ID: 22662
           Summary: ICE caused by forward reference
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: snarwin+bugzilla@gmail.com

As of DMD 2.098.1, the following program fails to compile:

---
enum isHashable(T) = __traits(compiles, T.init.tupleof[0][0].sizeof);

struct SumType(Types...)
{
    union Storage
    {
        Types values;
    }

    Storage storage;

    static if (isHashable!(Types[0])) {}
}

string[] toLines(Expression val) {
    return [];
}

alias Expression = SumType!(Scope, Return);

struct Return {
    Expression* _expr = new Expression;
}

struct Scope {
    Expression[] statements;

    string[] toLines() {
        return Expression.init.toLines;
    }
}
---

When attempting to compile, DMD gives the following output:

---
Error: unknown, please file report on issues.dlang.org
---

Any further reduction of the example program either causes compilation to succeed, or results in a different error.

--