You don’t need that mutating for-loop, @kwdef is designed to allow you to instantiate with compatible keyword arguments and input types, e.g. p = Parameters(;kwargs...). The only practical difference is the custom error message for incompatible keywords being specific to bar2 rather than the internal Parameters, and if you want to keep that, you can check issubset(keys(kwargs), fieldnames(Parameters)) before you instantiate at all.
1 Like