Skip to content

Commit

Permalink
Prevent "forward reference" errors when using parseAs.
Browse files Browse the repository at this point in the history
Because NestedFieldRef references the parent's (FR) Name/FieldName,
it causes a circular reference error with `parseAs`.
  • Loading branch information
Geod24 authored and omerfirmak committed Aug 23, 2022
1 parent 9ffb484 commit 110cc06
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions source/configy/FieldRef.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down

0 comments on commit 110cc06

Please sign in to comment.