Skip to content

Commit

Permalink
#502 added type checks for new_object() .parent argument enforcing S7…
Browse files Browse the repository at this point in the history
…_object and prohibiting S7_class passing.
  • Loading branch information
Tom Schwarzl committed Nov 22, 2024
1 parent 3a18a56 commit e7d1ac8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions R/class.R
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ is_class <- function(x) inherits(x, "S7_class")

# Object ------------------------------------------------------------------

#' @param .parent,... Parent object and named properties used to construct the
#' object.
#' @param .parent,... Parent S7 object and named properties used to construct
#' the object.
#' @rdname new_class
#' @export
new_object <- function(.parent, ...) {
Expand All @@ -253,7 +253,15 @@ new_object <- function(.parent, ...) {
}

# force .parent before ...
# TODO: Some type checking on `.parent`?
# TODO: Some additional type checking on `.parent`?

if (!inherits(.parent, "S7_object"))
stop("`.parent` needs to be an S7_object")
if (inherits(.parent, "S7_class")) {
stop(paste("`.parent` cannot be of type S7_class. Did you type",
"`.parent = S7_object` instead of `.parent = S7_object()`?"))
}

object <- .parent

args <- list(...)
Expand Down

0 comments on commit e7d1ac8

Please sign in to comment.