You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Child class property setters that mask parent class properties are unused at construction #585
Calling the child constructor does not ever hit the child property setter.
child(z=1)
<child>
@ x: int(0)
@ y: chr(0)
@ z: num 1
I would expect that calling child(z = 1) would use the child property setter and throw the error, but it seems that the parent constructor is used then the value is type checked against the child property class without ever using the child setter.
I spent some time investigating this. At least as far as I've interpreted the intended use cases, there seems to be two contradictory goals:
properties should be able to be specialized in child classes (child property behaviors mask parent behaviors)
constructors should be hierarchical (constructing a parent object first, then apply child constructors)
Assuming we don't want to totally throw a wrench in the current hierarchical construction model, I think the best approach would be to ignore setter functions during construction of a new object -- similar to how prop<- is called with check = FALSE so that the object is only validated at the end of construction. Similarly, we could then "set" each value with whatever value it received at that point to trigger the individual setter functions.
In this way, the constructors still get evaluated bottom up (first calling parent constructors and then the child constructors) without triggering setter functions, then the setters are evaluated top down (giving priority to children that mask parent properties).
This would require disabling setters and object validation for any parent constructors when an object is constructed, then running setters following masking rules, then finally doing object validation recursively.
Was interested in exploring this a bit more and made a fix over in dgkf/S7. It's a substantial change to the way that object construction (new_object()) works which certainly requires more detailed review before being considered so I just left it over there and tried to annotate the changes with rationale.
This would address the issue with the setters as well as the default values mentioned in the other issues.
It is nearly non-breaking. There are some minor edge cases that affect custom constructors which rely on positional arguments to new_object(). I think that these are necessary breakages to support property masking.
Activity
dgkf commentedon Dec 16, 2025
I spent some time investigating this. At least as far as I've interpreted the intended use cases, there seems to be two contradictory goals:
Assuming we don't want to totally throw a wrench in the current hierarchical construction model, I think the best approach would be to ignore setter functions during construction of a new object -- similar to how
prop<-is called withcheck = FALSEso that the object is only validated at the end of construction. Similarly, we could then "set" each value with whatever value it received at that point to trigger the individual setter functions.In this way, the constructors still get evaluated bottom up (first calling parent constructors and then the child constructors) without triggering setter functions, then the setters are evaluated top down (giving priority to children that mask parent properties).
This would require disabling setters and object validation for any parent constructors when an object is constructed, then running setters following masking rules, then finally doing object validation recursively.
hadley commentedon Dec 17, 2025
I think this is probably the same basic issue as #570/#467.
dgkf commentedon Dec 17, 2025
Was interested in exploring this a bit more and made a fix over in dgkf/S7. It's a substantial change to the way that object construction (
new_object()) works which certainly requires more detailed review before being considered so I just left it over there and tried to annotate the changes with rationale.This would address the issue with the setters as well as the default values mentioned in the other issues.
It is nearly non-breaking. There are some minor edge cases that affect custom constructors which rely on positional arguments to
new_object(). I think that these are necessary breakages to support property masking.Improve construction of subclasses (RConsortium#694)