-
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
Type checking for dynamic properties #450
Comments
This overlaps with the library(S7)
Foo <- new_class("Foo", properties = list(
double = new_property(
class_double,
getter = function(self) "not a double"
)
))
Foo
#> <Foo> class
#> @ parent : <S7_object>
#> @ constructor: function() {...}
#> @ validator : <NULL>
#> @ properties :
#> $ double: <double>
Foo()
#> <Foo>
#> @ double: chr "not a double" |
I guess (4) would be to not skip dynamic properties during object validation. They're probably skipped for performance reasons, but that might not be a good enough reason. It's likely that checking a property on every access, option (3), would have a bigger impact than just checking them during validation. Of course, checking them on every access is the only way to guarantee that they are valid. |
I think we can make a variation on (1) — that a conflict between the declared type and the provided type is undefined behaviour that the class developer needs to fix. |
The conclusion we reached in #451 means that |
Hmmmm, I wonder if we should check them at development-time but not use-time? (i.e. because only the class developer can fix such a problem). But I don't know how we could make that distinction. |
I would stick with (1) for now, assuming they are correct. Dynamic properties are essentially sugar for an accessor. We've never considered checking the return value on those. The class developer can always check them in the class-level validator. |
Dynamic properties currently lack type checking:
Options:
class
remains informative in printouts but is not enforced.class == class_any
if agetter
is supplied tonew_property()
.getter
before returning fromprop()
.The text was updated successfully, but these errors were encountered: