Open SouHanaQiao opened 7 months ago
@SouHanaQiao thanks for this PR, the original reason for generating different initializers was optimization, i.e. if there is no data provided for int2
in your example it won't be re-initialized again. This is also what the compiler follows when generating memberwise initializers. Can you provide what benefits your change will provide by removing this optimization?
Also, it seems like with your change int2
is using assigned value as default value even without user input for Default
value macro. I don't want this default behavior with this library as the default expectation for users are decoding failure error unless they want to override with a default value.
1. Mutable variables can have default values added by adding initialization syntax.
We can get the default value whether it is a surface value or an expression from
binding.initializer?.value
. Like this:int1
default value is an integer literal.int2
default value is a function expression.int3
default value is a variable reference.2. Usage:
3. The expanded results are as follows:
As expected except there are too many initialization methods. But the next step can be to just generate an initializing constructor containing all parameters with default values.