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
Extending a parent class with inconsistent properties #352
This doesn't error when you create the class, but it's not possible to construct it because there's no value that will satisfy the validator of both foo1 and foo2:
foo2(x=1L)
#> Error: <foo2> object properties are invalid:#> - @x must be <character>, not <integer>
foo2(x="x")
#> Error: <foo1> object properties are invalid:#> - @x must be <integer>, not <character>
Should we make this a define-time error? In principle, I think it's ok for a child class to make a property more restrictive than the parent class, but there's no way to test for test for this in general (since the restriction may occur at the validator level).
I think this should probably be a warning, not an error. For example, imagine that pkg A defines class A and pkg B defines class B which extends class A. If pkg A introduces a new field that conflicts with pkg B, you can continue to somewhat use pkg B (i.e. you only error where there are direct conflicts with the semantics, not at every instantiation).
Similarly if you accidentally introduce a conflict in your own package, it's generally easy to debug if you get a clear warning rather than an error which causes all code loading to fail.
WG call suggested that it should be an error if the child property class is not a subclass of parent property class, i.e. we only allow narrowing of types. (This only works if the property is largely read only, but that's a common case) Otherwise, it's silent.
Activity
hadley commentedon Sep 14, 2023
I think this should probably be a warning, not an error. For example, imagine that pkg A defines class A and pkg B defines class B which extends class A. If pkg A introduces a new field that conflicts with pkg B, you can continue to somewhat use pkg B (i.e. you only error where there are direct conflicts with the semantics, not at every instantiation).
Similarly if you accidentally introduce a conflict in your own package, it's generally easy to debug if you get a clear warning rather than an error which causes all code loading to fail.
hadley commentedon Oct 16, 2023
This is a more subtle example of the issue:
Narrowing might also happen through the validator:
hadley commentedon Oct 16, 2023
WG call suggested that it should be an error if the child property class is not a subclass of parent property class, i.e. we only allow narrowing of types. (This only works if the property is largely read only, but that's a common case) Otherwise, it's silent.
hadley commentedon Nov 23, 2023
Something like this:
But need to start with definition of
class_extends()Check that overridden properties narrow the type specification (#691)