diff --git a/src/library/tools/R/QC.R b/src/library/tools/R/QC.R index 6c99a7edb2..af665fd6c9 100644 --- a/src/library/tools/R/QC.R +++ b/src/library/tools/R/QC.R @@ -2379,6 +2379,39 @@ function(x, ...) res } +### Additional functions for checkS3methods +checkTopLevelCall <- function(expr, fun_name) { + if (inherits(expr, "if") || !is.call(expr)) { + return(FALSE) + } + fun_name <- as.name(fun_name) + fun_called <- expr[[1]] + if (is.call(fun_called)) { + inner_called <- fun_called[[1]] + if (identical(inner_called, quote(`:::`)) || + identical(inner_called, quote(`::`))) { + fun_called <- fun_called[[3]] + } + } + identical(fun_called, fun_name) +} + +containsTopLevelCall <- function(x, fun_name) { + fun_body <- body(x) + if (inherits(fun_body, "{")) { + any(vapply(fun_body, checkTopLevelCall, TRUE, fun = fun_name)) + } else { + checkTopLevelCall(fun_body, fun_name) + } +} + +isDeprecated <- function(fun) { + containsTopLevelCall(fun, quote(.Deprecated)) +} +isDefunct <- function(fun) { + containsTopLevelCall(fun, quote(.Defunct)) +} + ### * checkS3methods checkS3methods <- @@ -2603,6 +2636,11 @@ function(package, dir, lib.loc = NULL) function(g) { methods <- gen_dot_cls_matches(g, functions_in_code) + method_funs <- + Filter(Negate(function(x) { + isDefunct(x) || isDeprecated(x) + }), mget(methods, code_env)) + methods <- names(method_funs) if((n <- length(methods)) > 0L) { gargs <- nfg(g, code_env) entries <-