I've got the following module dummy.dummy.d
:
module dummy;
@safe:
@nogc:
struct Dummy
{
// TODO: Why do I need to repeat those? Aren't the formers still effective for inner scopes?
@safe:
@nogc:
static const int MAX_MEMBER_INT = 3;
int memberInt;
string memberStr;
this(int memberInt, string memberStr) nothrow
in
{
assert(memberInt > MAX_MEMBER_INT);
}
out
{
assert(this.memberInt == memberInt);
assert(this.memberStr == memberStr);
}
do
{
this.memberInt = memberInt;
this.memberStr = memberStr;
}
int doStuff() pure nothrow
{
auto result = this.memberInt - 1;
if (result <= MAX_MEMBER_INT)
result = 1 + MAX_MEMBER_INT;
return result;
}
}
I've also got the following module dummy.test.d
:
module test;
@safe:
@nogc:
private:
version (unittest)
{
import dummy;
/// Test [cg.math.dummy.dummy.Dummy.doStuff()]
unittest
{
Dummy instance = Dummy(4, "A dummy string");
assert(instance.doStuff() > Dummy.MAX_MEMBER_INT);
}
}
My question is:
>In the source file dummy.dummy.d
, why the first labelled attributes @safe
and @nogc
have no effect inside the struct's scope? In other words, why do I need to repeat labelled attributes statements in order to affect inner scopes?
To test this, simply remove in dummy.dummy.d
the TODO comment and its following labelled attributes.