unittest + struct ctorю + nested mixin template + alias
ref2401
refactor24 at gmail.com
Tue May 7 07:58:09 PDT 2013
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?
More information about the Digitalmars-d-learn
mailing list