Skip to content

Type inference: Add support for named arguments - #22973

Draft
hvitved wants to merge 3 commits into
github:mainfrom
hvitved:type-inference-named-args
Draft

hvitved wants to merge 3 commits into
github:mainfrom
hvitved:type-inference-named-args

Conversation

@hvitved

@hvitved hvitved commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions github-actions Bot added Rust Pull requests that update Rust code Unified labels Nov 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Argument matching mishandles repeated Swift labels and labelled enum-case parameters, producing spurious return types and breaking generic type propagation.

2 open issues
What changed in this PR

Adds named-argument matching to shared type inference, enabling Swift to infer argument types when earlier defaulted parameters are omitted.

Changes:

  • Exposes argument names and parameter labels through the inference interfaces.
  • Adds label-based matching while retaining positional arguments for Rust.
  • Updates Swift test annotations and generated inference expectations.
File Description
unified/​ql/​test/​library-tests/​type-inference/​type-inference.expected Records inferred argument-node types and improved closure typing.
unified/​ql/​test/​library-tests/​type-inference/​constructors.swift Updates an inline expectation comment for closure parameter inference.
unified/​ql/​lib/​codeql/​unified/​internal/​typeinference/​TypeInference.qll Introduces named argument wrappers and receiver handling.
unified/​ql/​lib/​codeql/​unified/​internal/​ParameterEx.qll Exposes external names for source and synthesized parameters.
shared/​typeinference/​codeql/​typeinference/​internal/​TypeInference.qll Matches arguments to parameters by name or position.
rust/​ql/​lib/​codeql/​rust/​internal/​typeinference/​TypeInference.qll Adapts positional-only Rust arguments to the shared interface.

Review effort: Max

pragma[nomagic]
additional AccessPosition getArgumentPosition(Invocation i, Argument arg) {
exists(int pos | arg = i.getArgument(pos) |
result.asNamed() = arg.getName()

AstParameterEx() { this = TAstParameter(p) }

override string getExternalName() { result = p.getExternalName() }

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

Rust Pull requests that update Rust code Unified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants