Is it possible to use an UDA to generate a struct inside a class ?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jan 1 13:15:27 PST 2015


On 01/01/2015 09:35 AM, Basile Burg wrote:

 > On Tuesday, 30 December 2014 at 19:18:41 UTC, Basile Burg wrote:

 > an ICE (every
 > compiler crash is an ICE right ?),

Yes, the compiler should never crash but produce an error message. 
Please report it preferably with a reduced code sample:

   https://issues.dlang.org/

 > not tested on trunk:

It has the same problem on git head.

 >
 > http://dpaste.dzfl.pl/70ab707b21e4
 >
 > e.g I try to get the getter delegate in order to set a new
 > izPropDescriptor in an AA.

         foreach(m; __traits(allMembers, tp)) {
             foreach(o; __traits(getOverloads, tp, m)) {
                 foreach(attr; __traits(getAttributes, o)) {
                     static if (is(attr == get)) {
                         writeln(attr.stringof, " < ", m);
                         alias PT = ReturnType!o;
                         //auto ICE = &o; //comment = no crash

You realize, all of those foreach'es are processed at compile-time for 
code generation. There will be no 'o' at run time; so its address cannot 
be used. The compiler problem is probably related to that.

                     } else if (is(attr == set)) {

You probably want that to be 'else static if'. Otherwise, when the 
previous 'static if' fails the condition, there will be an 'if' 
statement inserted, which would get executed at run time.

void main(string args[]){

Compiling with the -w compiler switch produces the following warning:

Warning: instead of C-style syntax, use D-style syntax 'string[] args'

Ali



More information about the Digitalmars-d-learn mailing list