diff --git a/source/configy/read.d b/source/configy/read.d index 5f842a6..5a75785 100644 --- a/source/configy/read.d +++ b/source/configy/read.d @@ -822,6 +822,14 @@ package FR.Type parseField (alias FR) ); } } + else static if (is(FR.Type == T*, T)) + { + // Allocate and parse pointers' values. + auto value = new T; + *value = node.parseField!(NestedFieldRef!(T, FR))( + path, T.init, ctx); + return value; + } else { static assert (!is(FR.Type == union), diff --git a/source/configy/test.d b/source/configy/test.d index 330acbf..072a4dd 100644 --- a/source/configy/test.d +++ b/source/configy/test.d @@ -965,3 +965,21 @@ ds: catch (ConfigException exc) assert(exc.toString() == "/dev/null(1:11): es.enabled: Expected to be a value of type bool, but is a scalar"); } + +/// Test pointers +unittest +{ + static struct N { + @Optional int value; + @Optional N* left, right; + } + auto c = parseConfigString!N(`left: + left: + value: 1 +right: + value: 2 +`, "/dev/null"); + assert(c.left.left.value == 1); + assert(c.left.right is null); + assert(c.right.value == 2); +}