AllNonNull

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

struct AllNonNull

Examples

1 class Class
2 {
3     @AllNonNull
4     Object[] objs;
5 
6     this(Object[] objs)
7     {
8         this.objs = objs;
9     }
10 
11     mixin(GenerateInvariants);
12 }
13 
14 (new Class(null)).objs.shouldEqual(Object[].init);
15 (new Class([null])).shouldThrow!AssertError;
16 (new Class([new Object, null])).shouldThrow!AssertError;

@AllNonNull may be used with associative arrays.

1 class Class
2 {
3     @AllNonNull
4     Object[int] objs;
5 
6     this(Object[int] objs)
7     {
8         this.objs = objs;
9     }
10 
11     mixin(GenerateInvariants);
12 }
13 
14 (new Class(null)).objs.shouldEqual(null);
15 (new Class([0: null])).shouldThrow!AssertError;
16 (new Class([0: new Object, 1: null])).shouldThrow!AssertError;

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

1 class Class
2 {
3     @AllNonNull
4     int[Object] objs;
5 
6     this(int[Object] objs)
7     {
8         this.objs = objs;
9     }
10 
11     mixin(GenerateInvariants);
12 }
13 
14 (new Class(null)).objs.shouldEqual(null);
15 (new Class([null: 0])).shouldThrow!AssertError;
16 (new Class([new Object: 0, null: 1])).shouldThrow!AssertError;

Meta