pub(crate) fn build_match_arg_prelude(
inputs: &Punctuated<FnArg, Comma>,
per_param: &HashMap<String, ParamAttrs>,
c_ident: &str,
attribution: CallAttribution,
) -> Vec<String>Expand description
Build R prelude lines that validate match_arg / choices / several_ok
parameters before the .Call().
Returns an empty vector when the method declares none. Every form is one
statement from CallAttribution::match_arg_statement with the method’s
own attribution: the strict scalar helper (NULL and the formal default
select the first choice, a factor is read as its labels), the Option<T>
form that skips it for NULL (#1473), and the strict several_ok helper
(every element must match, NULL selects all; #1472). An Either layer,
over a scalar or a several_ok list (#1612), guards either helper with
is.character(x) || is.factor(x), so everything else reaches the R
arm; Missing adds !missing(x) (#1551), and for a single choice
!identical(x, <choices>) (#2152). For match_arg the
choice list is the write-time placeholder (c_ident keys it, the same one
effective_r_defaults puts in the formal); for choices(...) it is the
literal.
The match_arg statements come first, then the choices(...) ones, each
group in signature order (inputs), as in a standalone function’s wrapper.
Shared by MethodContext::match_arg_prelude (inherent impls) and
TraitMethodContext::match_arg_prelude (trait impls) — see
audit/2026-07-03-dogfooding-macros-codegen.md finding #1 (trait methods
previously had no match_arg support at all).