Skip to content

Unified: Support optional parameters in legacy MaD signatures - #23229

Draft
asgerf wants to merge 2 commits into
mainfrom
asgerf-legacy-mad-optional-params
Draft

asgerf wants to merge 2 commits into
mainfrom
asgerf-legacy-mad-optional-params

Conversation

@asgerf

@asgerf asgerf commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Legacy MaD models identify methods by their argument labels, e.g. init(contentsOf:encoding:). Matching was by exact label equality, so a call that omits a defaulted argument (String(contentsOf: url)) never matched the model for the full signature.

This adds a ? suffix to mark a parameter as optional in the model name, e.g. init(contentsOf:encoding?:) or positional(_:_?:).

Approach

  • Join: calls and selectors are joined on method name (or type, for constructors) plus their named labels, ignoring positional _ labels and any label that is optional for some selector with that method name. Calls with only positional arguments therefore effectively join on name alone.
  • Final check: since the join is lossy, the full call labels are checked afterwards: exact equality for selectors without ?, otherwise a regexp derived from the selector (e.g. contentsOf:(encoding:)?).
  • Callables (for Parameter[...] sources) are matched exactly against the selector labels with ? stripped, since an overriding declaration must declare all parameters.
  • Setter calls keep their extra #newValue: label, which participates in both the join and the full check.

No existing model files are changed to use ?.

Tests

library-tests/mad gains models and Swift cases for optional named, positional, mixed and constructor parameters, a source on an override, and a same-name model with a required parameter. Negative cases cover unknown labels, wrong order, missing required arguments, too many/few positional arguments, and missing labels.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant