diff --git a/R/constructor.R b/R/constructor.R index 63df1e78..738555df 100644 --- a/R/constructor.R +++ b/R/constructor.R @@ -61,7 +61,12 @@ constructor_args <- function(parent, properties = list()) { if (is_class(parent) && !parent@abstract) { # Remove any parent properties; can't use parent_args() since the constructor # might automatically set some properties. - self_arg_nms <- setdiff(self_arg_nms, names2(parent@properties)) + parent_prop_nms <- names2(parent@properties) + overridden <- intersect(self_arg_nms, parent_prop_nms) + for(name in overridden) + parent_args[[name]] <- prop_default(properties[[name]]) + + self_arg_nms <- setdiff(self_arg_nms, parent_prop_nms) } self_args <- as.pairlist(lapply( diff --git a/tests/testthat/test-constructor.R b/tests/testthat/test-constructor.R index 02152dc3..3b744885 100644 --- a/tests/testthat/test-constructor.R +++ b/tests/testthat/test-constructor.R @@ -193,3 +193,19 @@ test_that("Dynamic settable properties are included in constructor", { expect_equal(foo@dynamic_settable, 1) }) + + +test_that("Child classes can change property default value", { + + Foo1 = new_class("Foo1", properties = list( + bar = class_vector + )) + + Foo2 = new_class("Foo2", Foo1, properties = list( + bar = new_property(default = 99) + )) + + expect_identical(formals(Foo1), pairlist(bar = logical())) + expect_identical(formals(Foo2), pairlist(bar = 99)) + +})