Bug?: Presence of "init()" Method Causes std.array.appender to Fail to Compile

Vijay Nayar madric at gmail.com
Sun May 13 23:53:58 UTC 2018


I encountered a very unexpected error when working on a project.  
It seems that the Appender and RefAppender structs created from 
the std.array.appender() method are sensitive to the mere 
presence of a method called "init()" on the element type of the 
array.

Here is a minimal example:

```
import std.array;

struct S1 {
   // The mere presence of this method causes the error, deleting 
it fixes the error.
   void init(string p1, int p2, int p3) { }
}

struct S2 {
   S1[] a;
   RefAppender!(int[]) getAppender() {
     return appender(&a);
   }
}

void main() { }
```

The compiler produces the following output:
```
/dlang/dmd/linux/bin64/../../src/phobos/std/array.d(2907): Error: 
cannot have array of `void(string, int, int)`
/dlang/dmd/linux/bin64/../../src/phobos/std/array.d(2976): Error: 
cannot have array of `inout void(string, int, int)`
/dlang/dmd/linux/bin64/../../src/phobos/std/array.d(3369): Error: 
template instance `std.array.Appender!(S1[])` error instantiating
/dlang/dmd/linux/bin64/../../src/phobos/std/array.d(3879):        
instantiated from here: `RefAppender!(S1[])`
onlineapp.d(12):        instantiated from here: `appender!(S1[]*, 
S1)`
/dlang/dmd/linux/bin64/../../src/phobos/std/array.d(3429): Error: 
cannot have array of `inout void(string, int, int)`
```

Is this a bug or a misunderstanding on my part?


More information about the Digitalmars-d mailing list