Skip to content

Commit

Permalink
fix S4 lookup in debugcall() (PR#18143)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@86532 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
smeyer committed May 11, 2024
1 parent 56d66b1 commit abe6259
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doc/NEWS.Rd
Expand Up @@ -108,6 +108,10 @@
\item The internal help server on Windows can again serve requests
sent in quick succession, fixing a regression in \R 4.4.0.
\item \code{debugcall(\var{S3Generic}())} now also works when a
corresponding S4-generic version is in the \pkg{methods} cache
(\PR{18143}).
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/library/utils/R/debugcall.R
@@ -1,7 +1,7 @@
## File src/library/utils/R/debugcall.R
## Part of the R package, https://www.R-project.org
##
## Copyright (C) 1995-2023 The R Core Team
## Copyright (C) 1995-2024 The R Core Team
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -30,7 +30,8 @@
mcall <- match.call(func, call)

env <- parent.frame(2L)
if(!(have.methods && methods::isGeneric(funsym))) { # not S4-generic
isS4Generic <- have.methods && methods::isGeneric(funsym, env)
if(!isS4Generic) {
s3ret <- isS3stdGeneric(func)
if(s3ret) {
genname <- names(s3ret)
Expand Down
17 changes: 17 additions & 0 deletions tests/reg-tests-1e.R
Expand Up @@ -1380,6 +1380,7 @@ stopifnot(exprs = {
})
## the last lost row.names => dim(.) was 0 x 3 instead of d0's 2 x 3, in R <= 4.4.0


## Scan should not treat "NA" as double/complex when na.strings doesn't
## include it (PR#17289)
(r <- tryCid(scan(text="NA", what=double(), na.strings=character())))
Expand All @@ -1388,6 +1389,22 @@ stopifnot(inherits(r, "error"))
stopifnot(inherits(r, "error"))


## PR#18143: debugcall(<S3Generic>()) when an S4-generic version is cached
stopifnot(exprs = {
isGeneric("summary", getNamespace("stats4"))
isNamespaceLoaded("stats4")
isS3stdGeneric(summary) # cached S4 generic is not visible
})
debugcall(summary(factor(1)))
## failed in R <= 4.4.0 with Error in fdef@signature :
## no applicable method for `@` applied to an object of class "function"
stopifnot(isdebugged(summary.factor))
undebug(summary.factor)
stopifnot(!isdebugged(summary.factor))
unloadNamespace("stats4")



## keep at end
rbind(last = proc.time() - .pt,
total = proc.time())

0 comments on commit abe6259

Please sign in to comment.