Skip to content

Commit e6d55bc

Browse files
author
maechler
committed
isGeneric(<primitive>, fdef=*, getName=TRUE) fix
git-svn-id: https://svn.r-project.org/R/trunk@87403 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 377e9b6 commit e6d55bc

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

doc/NEWS.Rd

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@
408408
\item Fix segfault on \code{quartz()} from \code{grid.glyph()}
409409
call with \code{glyphInfo()} that describes non-existent font
410410
(\PR{18784}). Thanks to \I{Tomek Gieorgijewski}.
411-
411+
412412
}
413413
}
414414
}
@@ -449,9 +449,13 @@
449449
vector and a logical, integer or double vector -- previously the
450450
inclusion of the latter was garbled.
451451
452-
\item \code{smooth.spline()} checks validoity of its arguements
452+
\item \code{smooth.spline()} checks validity of its arguments
453453
\code{df.offset} and \code{penalty}: it could segfault if they
454454
were \code{NULL}.
455+
456+
\item \code{isGeneric(<primitive>, fdef=*, getName=TRUE)} now also
457+
returns the name instead of just \code{TRUE}, fixing \PR{18829}
458+
reported by \I{Mikael Jagan}.
455459
}
456460
}
457461
}

src/library/methods/R/Methods.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,26 +267,26 @@ isGeneric <-
267267
## a successful search will usually end here w/o other tests
268268
if(!is.null(fdef))
269269
return(if(getName) fdef@generic else TRUE)
270-
}
270+
}
271271
if(is.null(fdef))
272272
fdef <- getFunction(f, where=where, mustFind = FALSE)
273273
if(is.null(fdef))
274274
return(FALSE)
275275
## check primitives. These are never found as explicit generic functions.
276276
if(is.primitive(fdef)) {
277-
## the definition of isGeneric() for a base function is that methods are defined
277+
## the definition of isGeneric() for such a function is that methods are defined
278278
## (other than the default primitive)
279279
gen <- genericForBasic(.primname(fdef), mustFind = FALSE)
280-
return(is.function(gen) && length(names(.getMethodsTable(gen))) > 1L)
280+
return(
281+
if(is.function(gen) && length(names(.getMethodsTable(gen))) > 1L)
282+
if(getName) gen@generic else TRUE
283+
else FALSE)
281284
}
282285
if(!is(fdef, "genericFunction"))
283286
return(FALSE)
284287
gen <- fdef@generic # the name with package attribute
285288
if(missing(f) || .identC(gen, f)) {
286-
if(getName)
287-
gen
288-
else
289-
TRUE
289+
if(getName) gen else TRUE
290290
}
291291
else {
292292
warning(gettextf(

tests/reg-tests-1e.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,16 @@ stopifnot(
16611661
)
16621662

16631663

1664+
## isGeneric(., getName = TRUE, ..) w/ or w/o fdef -- PR#18829
1665+
setClass("zzz")
1666+
setMethod("+", c(e1 = "zzz", e2 = "missing"), function(e1, e2) e1)
1667+
(gen <- isGeneric("+", fdef = `+`, getName = TRUE)) # wrongly returned just TRUE
1668+
stopifnot(identical(gen, isGeneric("+", getName = TRUE)), # the latter always worked
1669+
identical(gen, structure("+", package = "base")),
1670+
isGeneric("+"), isGeneric("+", fdef = `+`))
1671+
1672+
1673+
16641674
## keep at end
16651675
rbind(last = proc.time() - .pt,
16661676
total = proc.time())

0 commit comments

Comments
 (0)