Repository navigation
Fill in DefaultVal fields wrapped in Short, Positional or Description - #21
clockblocker wants to merge 1 commit into
Conversation
9938e6a to
edb4023
Compare
367cd89 to
e420408
Compare
edb4023 to
587c49f
Compare
e420408 to
50295f7
Compare
587c49f to
426be1c
Compare
|
AI-drafted: On main, an This PR fills those defaults in. To stay compatible, it does so only when That is the situation raised in munich-data-engineering#786 (comment): adding a sibling field without a default constructor, or with one that throws, silently changes what the Would you rather a wrapped |
50295f7 to
a773321
Compare
426be1c to
5ab0a7a
Compare
Fields such as rfl::Short<"o", rfl::DefaultVal<T>>, rfl::Positional<rfl::DefaultVal<T>> and rfl::Description<"...", rfl::DefaultVal<T>> were required by every reader, rfl::json::read and rfl::cli::read included, while the JSON schema listed them as optional without a default. internal::is_default_val_v now looks through Rename, Short, Positional, Description and Deprecated, in any order, and the schema sets the default on the DefaultVal node beneath Description and Deprecated. Compatibility: such a struct is now default-constructed before it is read, as one with a bare DefaultVal is. If it has no default constructor, or default construction throws, a struct whose only DefaultVal fields are wrapped is read as on main, without its defaults, with those fields required. A wrapped DefaultVal in an rfl::NamedTuple, or in a struct with atomic fields read through a pointer, stays required, so such code keeps compiling. Co-Authored-By: Claude Opus 5.5 <[email protected]>
a773321 to
089d517
Compare
5ab0a7a to
8313ff3
Compare
Summary
Makes
rfl::DefaultVal<T>work when wrapped insiderfl::Short,rfl::Positional,rfl::Description,rfl::Rename, orrfl::Deprecated(in any order). Previously, readers treated wrappedDefaultValfields as required while JSON Schema marked them optional without a"default".Related: comment on munich-data-engineering/reflect-cpp#534.
Example
Key details
internal::is_default_val_vlooks throughRename,Short,Positional,Description, andDeprecatedin any order."default"beneathDescriptionandDeprecatedwrappers too.DefaultValfields and cannot be default-constructed (orT{}throws), it falls back tomain's behavior (fields required) instead of breaking existing code. BareDefaultValstillstatic_asserts without a default constructor and errors ifT{}throws.DefaultValinrfl::NamedTupleor structs withstd::atomicbehind smart pointers stays required/compiling as onmain.default_val.mdandcli.md.Open question: should wrapped
DefaultValmatch bareDefaultValstrictly (static_assertwithout a default constructor, error whenT{}throws) instead of falling back? (See comment below.)AI-authored. Base:
main(after munich-data-engineering#786).