is there some know bugs with traits, type and library?

Ali Çehreli acehreli at yahoo.com
Fri Jun 24 10:26:11 PDT 2011


On Sat, 25 Jun 2011 00:53:16 +1000, Lloyd Dupont wrote:

> I have code like that:
> ----
> module main;
> 
> import std.variant;
> import std.stdio;
> import std.metastrings : Format;
> import std.traits;
> 
> public mixin template property(T, string name) {
>     mixin(Format!("private T _%s;
>                   @property public T %s() { return _%s; } @property
>                   public void %s(T value) { _%s = value; }", name,
> name, name, name, name));
> }
> 
> interface IInter
> {
> }
> 
> class Foo : IInter
> {
>     static this()
>     {
>         Compiled!(Foo, "FP");
>         Compiled!(Foo, "Subfoo");
>     }
> 
>     @property public Foo FP() { return new Foo(); } @property public
>     void FP(Foo f) { }
> 
>     mixin property!(Foo, "Subfoo");
> }
> 
> int main(string[] argv)
> {
>     Foo f = new Foo();
>     __traits(getMember, f, "FP") = new Foo(); return 0;
> }
> void Compiled(T, string memberName)() {
>     T t;
>     writeln(mixin( "__traits(compiles, t." ~memberName ~" = ("
> ~typeof(__traits(getMember, T, memberName)).stringof  ~").init)" ));
>     //writeln((__traits(getMember, t, memberName) =
> typeof(__traits(getMember, T, memberName)).init).stringof); }
> ----
> This sample works fine, and print "true" twice!

For me too.

> However in my real
> program, which span a couple of static library and 1 exe,

Are you trying to say that you can't reproduce it with this simplified 
code? Or should we change something to see the problem?

> it print false
> if my property are of objet type (as opposed to int, string, etc...)
> i.e. the reflection library seems to think that mixin(
> "__traits(compiles, t." ~memberName ~" = (" ~typeof(__traits(getMember,
> T, memberName)).stringof  ~").init)" )
> 
> evaluate to false if typeof(__traits(getMember, T, memberName) is a
> class... any ideas?

I was able to get

false
true

by changing the return type of FP():

    @property public IInter FP() { return new Foo(); }

Is that the problem? .init of derived not being assignable to base?

Ali


More information about the Digitalmars-d mailing list