Forgot to write it here as well, but essentially I now implemented a 
compile-time checker that you fully assign to every field in your mapping 
procedure. It essentially keeps a list of all fields it can automatically map 
from the parameters to the fields of the desired object and then checks for the 
assignments that happen within the proc. The assignments can be as complex as 
they want, I recursively check for all `nnkAsgn` nodes, which should get all of 
them regardless of what happens.

If the combination of those two lists is the entire set of fields on the 
desired object, you pass, else you get a compiler-error. No more "Oh, I forgot 
to assign here so now that field is 0/""/@[]/nil". For the most part anyway.

There are 2 edge-cases where I don't quite get how to solve them without it 
being insanely complicated:

1) How to ensure that you assign to every field of an object when if/case 
statements are involved. The problem here is you might have field `a` on the 
desired object type `A` and you only assign to it if `A.b > 5`, but you forgot 
to assign something if `A.b < 5`. How I could catch that in a simple way I 
don't know.

2) object variants For object variants, when they are used for mapping it 
counts **all** their fields, including their variant fields, for mapping. So if 
your result-type `A` has the field `a` but the object variant you use as 
parameter has `a` only in 1 of its variants and you don't assign to `A.a` when 
your variant is of a kind that does not have `a`, then I can't catch that. I 
guess I should just not allow object variant fields to count to force the user 
to have explicit assignments for those fields?

As for when the result-type is an object variant - There you basically need to 
have fields and/or assignments to satisfy **every** field of an object variant, 
to make sure you can construct every kind of an object variant with all fields 
of it assigned to. I guess that works out well enough (?).

Reply via email to