www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - is there some know bugs with traits, type and library?

reply "Lloyd Dupont" <ld-REMOVE galador.net> writes:
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!
However in my real program, which span a couple of static library and 1 exe, 
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? 
Jun 24 2011
parent reply Ali =?iso-8859-1?q?=C7ehreli?= <acehreli yahoo.com> writes:
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
Jun 24 2011
parent "Lloyd Dupont" <ld-REMOVE galador.net> writes:
Exactly!
But I was able to reproduce the bug this morning simply by splitting it in 
an exe and lib, as I said.
Going to post it in another post!





"AliƇehreli"  wrote in message news:iu2hbj$gb6$2 digitalmars.com...

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