Being by no means an expert in the field, I do however know of solvers such as Z3 that can generate a correct program, provided you can express your constraints as a set of logical rules, such as here.
However, in the example given above, logical rules are designed "by hand" from a set of examples, so the "compilation step" from the examples to the set of rules must be done in the user's head.
Does a system automating this "compilation step" exist (i.e automated rule set deduction from a set of examples), that would allow the user to see and make use of the set of rules?