www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21984] New: duping a recursive ctfe param can crash dmd


          Issue ID: 21984
           Summary: duping a recursive ctfe param can crash dmd
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: destructionator gmail.com

This is weird and I don't even know how to describe it. Just try compiling this

struct ContainerMeta {
        string s;
        ContainerMeta[] children;

template Container(Thing) {
        class Container : Thing {
                static ContainerMeta opCall(ContainerMeta[] children...) {
                        return ContainerMeta(

//void main() {
        struct A { }

I get all this here:

/home/me/d/dmd2/linux/bin64/../../src/druntime/import/object.d(3473): Error:
cannot append type `const(ContainerMeta)` to type `ContainerMeta[]`
/home/me/d/dmd2/linux/bin64/../../src/druntime/import/object.d(3460): Error:
template instance `object._dup!(const(ContainerMeta), ContainerMeta)` error
instantiated from here: `_trustedDup!(const(ContainerMeta), ContainerMeta)`
bugctfe.d(11):        instantiated from here: `dup!(ContainerMeta)`
bugctfe.d(18):        instantiated from here: `Container!(Object)`
bugctfe.d(18): Error: CTFE failed because of previous errors in `opCall`

In the code I reduced this out of, dmd also segfaulted, but I couldn't
reproduce that in the minimized example.

Now, I also left that commented main() thing because if you uncomment that, it
all works fine. So apparently nested structs - including static nested structs
- are ok, but top-level thing is not.

My guess is probably some semantic order problem.

The variadic thing btw is secondary, I tried doing it with a plain array and
explicitly passing empty too and it failed.

Interestingly removing the `string s` also let it work. So very strange.

May 28