From 110cc0600324f091773d979284d2948a9ddbb975 Mon Sep 17 00:00:00 2001 From: Geod24 Date: Tue, 23 Aug 2022 01:30:47 +0200 Subject: [PATCH] Prevent "forward reference" errors when using `parseAs`. Because NestedFieldRef references the parent's (FR) Name/FieldName, it causes a circular reference error with `parseAs`. --- source/configy/FieldRef.d | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/source/configy/FieldRef.d b/source/configy/FieldRef.d index 1f654dc..fea7b20 100644 --- a/source/configy/FieldRef.d +++ b/source/configy/FieldRef.d @@ -113,8 +113,15 @@ unittest static assert(FieldRefTuple!(FieldRefTuple!(Config3)[0].Type)[1].Name == "notStr2"); } -/// A pseudo `FieldRef` used for structs which are not fields (top-level) -package template StructFieldRef (ST) +/** + * A pseudo `FieldRef` used for structs which are not fields (top-level) + * + * Params: + * ST = Type for which this pseudo-FieldRef is + * DefaultName = A name to give to this FieldRef, default to `null`, + * but required to prevent forward references in `parseAs`. + */ +package template StructFieldRef (ST, string DefaultName = null) { /// public enum Ref = ST.init; @@ -127,6 +134,11 @@ package template StructFieldRef (ST) /// public enum Optional = false; + + /// Some places reference their parent's `Name` / `FieldName` + public enum Name = DefaultName; + /// Ditto + public enum FieldName = DefaultName; } /// A pseudo `FieldRef` for nested types (e.g. arrays / associative arrays)