Skip to main content

check_replacement_value_param

Function check_replacement_value_param 

Source
pub(crate) fn check_replacement_value_param(
    generic: &str,
    inputs: &Punctuated<FnArg, Comma>,
    formals: &Formals,
    fallback: Span,
) -> Result<()>
Expand description

Check that an S3 method for a replacement generic takes the new value last, as value.

A replacement generic is one whose name ends in <- ($<-, [[<-, names<-). R calls it with the new value as a named argument (x$f <- v runs `$<-`(x, "f", value = v)), and R CMD check (tools::checkReplaceFuns()) requires the last formal of every replacement function, registered S3 methods included, to be value. The last non-receiver parameter of inputs that is an R formal (an NArgs parameter is none, #1860) must therefore become the R formal value (_value does too, as does a declared formal = "value", formals); a trailing &Dots is ..., so it can’t be last. Any other generic passes. fallback spans the error when there is no parameter to point at.

Used by standalone s3(generic = ..., class = ...) functions (lib.rs, once the condition-call markers have left the R formals) and by S3 impl-block instance methods (miniextendr_impl.rs).