NonInit

When a field is marked with @NonInit, field !is T.init is asserted.

struct NonInit

Examples

import core.time : Duration;

class Class
{
    @NonInit
    float f_;

    this(float f) { this.f_ = f; }

    mixin(GenerateInvariants);
}

(new Class(float.init)).shouldThrow!AssertError;

When <b>any</b> condition check is applied to a nullable field, the test applies to the value, if any, contained in the field. The "null" state of the field is ignored.

class Class
{
    @NonInit
    Nullable!float f_;

    this(Nullable!float f)
    {
        this.f_ = f;
    }

    mixin(GenerateInvariants);
}

(new Class(5f.nullable)).f_.isNull.shouldBeFalse;
(new Class(Nullable!float())).f_.isNull.shouldBeTrue;
(new Class(float.init.nullable)).shouldThrow!AssertError;

Conditions can be applied to static attributes, generating static invariants.

static assert(!__traits(compiles, ()
{
    class Class
    {
        @NonNull
        private static Object obj;

        mixin(GenerateInvariants);
    }
}), "invariant on static field compiled when it shouldn't");

Meta