Skip to content

Commit e7d1ac8

Browse files
author
Tom Schwarzl
committed
RConsortium#502 added type checks for new_object() .parent argument enforcing S7_object and prohibiting S7_class passing.
1 parent 3a18a56 commit e7d1ac8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

R/class.R

+11-3
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ is_class <- function(x) inherits(x, "S7_class")
238238

239239
# Object ------------------------------------------------------------------
240240

241-
#' @param .parent,... Parent object and named properties used to construct the
242-
#' object.
241+
#' @param .parent,... Parent S7 object and named properties used to construct
242+
#' the object.
243243
#' @rdname new_class
244244
#' @export
245245
new_object <- function(.parent, ...) {
@@ -253,7 +253,15 @@ new_object <- function(.parent, ...) {
253253
}
254254

255255
# force .parent before ...
256-
# TODO: Some type checking on `.parent`?
256+
# TODO: Some additional type checking on `.parent`?
257+
258+
if (!inherits(.parent, "S7_object"))
259+
stop("`.parent` needs to be an S7_object")
260+
if (inherits(.parent, "S7_class")) {
261+
stop(paste("`.parent` cannot be of type S7_class. Did you type",
262+
"`.parent = S7_object` instead of `.parent = S7_object()`?"))
263+
}
264+
257265
object <- .parent
258266

259267
args <- list(...)

0 commit comments

Comments
 (0)