11# File src/library/methods/R/Methods.R
22# Part of the R package, https://www.R-project.org
33#
4- # Copyright (C) 1995-2024 The R Core Team
4+ # Copyright (C) 1995-2025 The R Core Team
55#
66# This program is free software; you can redistribute it and/or modify
77# it under the terms of the GNU General Public License as published by
@@ -774,14 +774,20 @@ selectMethod <-
774774 cat(" * mlist environment with" , length(mlist )," potential methods\n " )
775775 if (length(signature ) < nsig )
776776 signature [(length(signature )+ 1 ): nsig ] <- " ANY"
777+ inGroups <- length(fdef @ group ) > 0L # " I belong to a group "
778+ maybeGrp <- function (meth ) { # meth: a function, possibly primitive, or method
779+ if (inGroups && isS4(meth ) && meth @ generic != fdef @ generic )
780+ attr(meth @ generic , " orig" ) <- fdef @ generic
781+ meth
782+ }
777783 if (identical(fdef @ signature , " ..." )) {
778784 method <- .selectDotsMethod(signature , mlist ,
779785 if (useInherited ) getMethodsForDispatch(fdef , inherited = TRUE ))
780786 if (is.null(method ) && ! optional )
781787 stop(gettextf(" no method for %s matches class %s" ,
782788 sQuote(" ..." ), dQuote(signature )),
783789 domain = NA )
784- return (method )
790+ return (maybeGrp( method ) )
785791 }
786792 method <- .findMethodInTable(signature , mlist , fdef )
787793 if (is.null(method )) {
@@ -805,7 +811,7 @@ selectMethod <-
805811 # # else list() : just look in the direct table
806812
807813 if (length(methods ))
808- return (methods [[1L ]])
814+ return (maybeGrp( methods [[1L ]]) )
809815 else if (optional )
810816 return (NULL )
811817 else stop(gettextf(" no method found for signature %s" ,
0 commit comments