-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix getter infinite recursion #406
Conversation
495792e
to
40451bc
Compare
R/constructor.R
Outdated
@@ -48,7 +48,7 @@ constructor_args <- function(parent, properties = list()) { | |||
|
|||
self_args <- names2(properties) | |||
# Remove dynamic arguments | |||
self_args <- self_args[vlapply(properties, function(x) is.null(x$getter))] | |||
self_args <- self_args[vlapply(properties, function(x) is.null(x$getter) || !is.null(x$default))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that a property with only a getter could be computed entirely dynamically, so we wouldn't want it in the constructor. I still think we should use the prototype approach, where the object just starts with its defaults, and there's no need to set a read-only property during construction.
Btw, there is actually a bug here, where a property with a setter (and a getter) is dropped, in error. This is addressed by the prop_is_read_only branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should the interface be for someone looking to implement a class with a property that can be set when the instance is initially constructed but is read-only after that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, this looks good to me: main...prop_is_read_only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See issue #404 for my proposed approach to construct-only properties.
Are you sure we can use the same list for both getting and setting? Assume a setter is called and it wants to get the value of the property, I think it would be surprising that the getter is not called. As an example of where this would arise, assume a property is fully dynamic, like the value is being stored in a database, or on a C data structure. Maybe the setter wants to make sure that the value is different before performing the change. I think we can still share a lot of the code between setting and getting, even if we use two different lists (the list symbol can just become an argument to the functions that manipulate the list). |
My thought process was that in property I'll change the approach to allow for that. |
Closes #403