Skip to content

Commit

Permalink
Use T.init, not null as array concatenation identity
Browse files Browse the repository at this point in the history
fixes bug where null ~ NullableTypeArray prepends a null value to the array.
  • Loading branch information
FeepingCreature committed Jan 12, 2018
1 parent 937de02 commit 82353aa
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/accessors.d
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ template GenerateReader(string name, alias field)
static if (needToDup)
{
return format("%s%s final @property auto %s() inout %s"
~ "{ return null ~ this.%s; }",
visibility, getModifiers!field, accessorName, attributesString, name);
~ "{ return typeof(this.%s).init ~ this.%s; }",
visibility, getModifiers!field, accessorName, attributesString, name, name);
}
else static if (isStatic!field)
{
Expand Down Expand Up @@ -184,7 +184,7 @@ template GenerateReader(string name, alias field)
"@nogc nothrow @safe { return this.foo; }");
static assert(GenerateReader!("foo", intArrayValue) ==
"public static final @property auto foo() inout nothrow @safe "
~ "{ return null ~ this.foo; }");
~ "{ return typeof(this.foo).init ~ this.foo; }");
}

template GenerateRefReader(string name, alias field)
Expand Down Expand Up @@ -911,3 +911,21 @@ unittest
}
}
}

unittest
{
class Class
{
}

struct Thing
{
@Read
private Class[] classes_;

mixin(GenerateFieldAccessors);
}

Thing thing;
assert(thing.classes.length == 0);
}

0 comments on commit 82353aa

Please sign in to comment.