pub(crate) fn s4_generic_guard(
generic: &str,
explicit: bool,
receiver: &str,
) -> StringExpand description
The line that defines an S4 instance method’s generic before its
setMethod(), shared by the inherent and trait generators.
A generic of the package’s own (explicit false) is defined unless this
namespace already has it. Unconditional setGeneric() would replace the
generic object and clear the methods other types registered on it, and the
check must be a namespace-local exists(): a bare isGeneric() searches
S4 metadata globally, so with an installed copy of the package attached,
load_all() would skip setGeneric() while setMethod() still can’t see
the generic from the namespace being loaded, and isGeneric(where =)
resolves the namespace to a package name, which fails mid-install (#1158).
An explicit generic = "..." may name a generic that lives elsewhere:
methods::show (an S4 generic exists() misses when methods is not
attached), the primitive length, base’s S3 summary. It is defined only
when no function of that name is visible and methods::isGeneric() finds
no generic of another package, with receiver as its dispatch formal;
otherwise setMethod() attaches to the existing one instead of masking it
with a function(x, ...) generic of this package (#1677). A generic whose
@package is this namespace’s name is an installed copy’s, the #1158 case,
so it is defined anyway. environmentName() is a plain lookup, unlike
isGeneric(where =). A name nothing defines is created, but gets no
generated page: whether it is the package’s own is only known at load time
(#2039).