Skip to content

Child class property setters that mask parent class properties are unused at construction #585

@dgkf

Description

@dgkf

Given a set of child-parent classes, where the child masks a parent property and adds a custom setter such as

parent <- new_class(
  "parent",
  properties = list(
    "x" = class_integer,
    "y" = class_character,
    "z" = class_any
  )
)

child <- new_class(
  "child",
  parent = parent,
  properties = list(
    "z" = new_property(
      class_double,
      setter = function(self, value) {
        stop("hey! don't set that!")
        self
      }
    )
  )
)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions