[Issue 24764] New: ICE when -vcg-ast prints imported invariant

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 12 13:25:53 UTC 2024


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

          Issue ID: 24764
           Summary: ICE when -vcg-ast prints imported invariant
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: ice
          Severity: normal
          Priority: P3
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dkorpel at live.nl

Reduced from `imported!"std.outbuffer"`:

```
// a.d
template imported()
{
    import imported = b;
}

alias x = imported!();
```

```
// b.d
struct O
{
    invariant() {}
}
```

When compiling `dmd -vcg-ast a.d` you get:

```
core.exception.AssertError at src/dmd/hdrgen.d(1863): Assertion failure
```

The code in question being:

```D
void visitInvariantDeclaration(InvariantDeclaration d)
    {
        if (hgs.hdrgen)
            return;
        if (stcToBuffer(buf, d.storage_class))
            buf.writeByte(' ');
        buf.writestring("invariant");
        if(auto es = d.fbody.isExpStatement())
        {
            assert(es.exp && es.exp.op == EXP.assert_); // FAILS, it's EXP.call
            buf.writestring(" (");
            (cast(AssertExp)es.exp).e1.expressionToBuffer(buf, hgs);
            buf.writestring(");");
            buf.writenl();
        }
        else
        {
            bodyToBuffer(d);
        }
    }
```

--


More information about the Digitalmars-d-bugs mailing list