[Issue 6211] New: __traits (compile) return wrong result when the bug happen

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jun 24 18:35:48 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6211

           Summary: __traits (compile) return wrong result when the bug
                    happen
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: ld at galador.net


--- Comment #0 from Lloyd Dupont <ld at galador.net> 2011-06-24 18:30:57 PDT ---
I'm using DMD2.053 on Windows7 x64

My test case:
- I have a all in one console application which output "true true"
- I have a project with the exact same code split into a static lib and an 
exe and it output "false false"

The bug is that the output is different!

=== first the all in one, outputing "true, true" =========
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)
{
    return 0;
}
void Compiled(T, string memberName)()
{
    T t;
    writeln(mixin( "__traits(compiles, t." ~memberName ~" = (" 
~typeof(__traits(getMember, T, memberName)).stringof  ~").init)" ));
}
==============================================


now the splitted program, outputting "false, false"
whereas it should output "true, true" just like above, shouldn't it!?!

===== lib.d ====
module lib;

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
{
}

void Compiled(T, string memberName)()
{
    T t;
    writeln(mixin( "__traits(compiles, t." ~memberName ~" = " 
~typeof(__traits(getMember, T, memberName)).stringof  ~").init" ));
}
====== main.d =====
module main;

import lib;

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)
{
    return 0;
}
===================== buildrun.bat =========
dmd -lib -g -debug -X -of"lib1.lib" lib.d
dmd -g -debug -X main.d lib1.lib
main
====================================

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list