Hi.

I've been building a reflection library for D, but I've hit a snag. If anyone can help out, it would be much appreciated =D

In the example below, the second line of main() retrieves the reflection of a base class. Everything is well and good. Now, I am trying to come up with a more pleasant syntax, which is the code that is commented out.

When I uncomment the nicer syntax, I get the errors below:

[1] Error: variable refl cannot be read at compile time
[2] Error: CTFE failed because of previous errors in base


class Base {
    double d = 0.4;
}

class Test : Base {
    int x = 4;
}

abstract class Refl {
    @property abstract string name() const;
    @property abstract string baseName() const;
}

class ClassRefl(T) : Refl {
    @property override string name() const {
        return T.stringof;
    }

    @property override string baseName() const {
        alias BaseClassesTuple!T base_types;
        return base_types[0].stringof;
    }
}

const(Refl) reflect(T)() {
    static const(Refl) refl = new ClassRefl!T;
    return refl;
}

const(Refl) reflect(string name)() {
    mixin("return reflect!(" ~ name ~ ");");
}

//const(Refl) base(const(Refl) refl) {
//    return reflect!(refl.baseName());        ERROR  [1]
//}

void main()
{
    static const(Refl) refl = reflect!Test;

    static const(Refl) baseRefl = reflect!(refl.baseName());

    //static const(Refl) baseRefl = refl.base;       ERROR  [2]

    writeln(refl.name);
    writeln(baseRefl.name);
}


If anyone can offer a work around it would be much appreciated.

Reply via email to