AllNonNull

When a field is marked with @AllNonNull, field.all!"a !is null" is asserted.

struct AllNonNull

Examples

class Class
{
    @AllNonNull
    Object[] objs;

    this(Object[] objs)
    {
        this.objs = objs;
    }

    mixin(GenerateInvariants);
}

(new Class(null)).objs.shouldEqual(Object[].init);
(new Class([null])).shouldThrow!AssertError;
(new Class([new Object, null])).shouldThrow!AssertError;

@AllNonNull may be used with associative arrays.

class Class
{
    @AllNonNull
    Object[int] objs;

    this(Object[int] objs)
    {
        this.objs = objs;
    }

    mixin(GenerateInvariants);
}

(new Class(null)).objs.shouldEqual(null);
(new Class([0: null])).shouldThrow!AssertError;
(new Class([0: new Object, 1: null])).shouldThrow!AssertError;

When used with associative arrays, @AllNonNull may check keys, values or both.

class Class
{
    @AllNonNull
    int[Object] objs;

    this(int[Object] objs)
    {
        this.objs = objs;
    }

    mixin(GenerateInvariants);
}

(new Class(null)).objs.shouldEqual(null);
(new Class([null: 0])).shouldThrow!AssertError;
(new Class([new Object: 0, null: 1])).shouldThrow!AssertError;

Meta