Version D 2.062

class MyClass
{}

struct MyStruct(T)
if (is(T == class))
{
        string _message = "nothing";

        this(T obj)
        {
                if (obj is null){
                        _message = "Null reference message";
                }
                else{
                        _message = "All right message";
                }
        }

        mixin Foo!();

        private mixin template Foo()
        {
                void foo() {}
        }
}


unittest
{
        alias MyStruct!MyClass StructType;
        auto inst = StructType(null);

        string msg = inst._message;             // Wrong value!
}


The behavior varies between executions: sometimes msg contains empty string, in other times it holds "nothing". If StructType is replaced with MyStruct!MyClass then everything works as expected.
        auto inst = MyStruct!MyClass(null);     // OK

If declaration of the Foo template is moved out of struct MyStruct(T) definition, everything works fine too. This strange behavior is observed only in unittest block, not when executed in main().
Am I doing something incorrectly or is this a bug?

Reply via email to