Repository navigation
Unified: Fix two bugs in parameter name scoping - #22960
Merged
Merged
Conversation
| predicate implicitDeclInScope(string name, AstNode scope) { implicitDeclInScope(name, scope, _) } | ||
|
|
||
| predicate accessCand(AstNode n, string name) { n.(PotentialLocalNameAccess).getName() = name } | ||
| predicate accessCand(AstNode n, string name) { |
asgerf
force-pushed
the
unified/func-param-clash
branch
from
October 30, 2026 14:00
959ff4f to
67db149
Compare
No semantic
This turned out not to be needed for the fix I was working on, but it seemed like a worthwhile simplification to land anyway.
asgerf
force-pushed
the
unified/func-param-clash
branch
from
November 11, 2026 09:45
67db149 to
60a4adb
Compare
resolveId only accepted Identifier, but SuperExpr is also a PotentialLocalNameAccess. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Parameters share the body’s scope with local functions, making bindings and calls ambiguous when a local function shadows a parameter.
1 open issue
What changed in this PR
This PR updates unified name binding to separate parameters from enclosing function names and prevent Swift parameter defaults from resolving to parameters.
Changes:
- Moves parameter bindings to callable-body scope and resolves binding identifiers through their declared scopes.
- Exposes name-and-scope matching for all shared local entities.
- Adds Swift regression cases for matching function/parameter names and default-value lookup, alongside fixture formatting.
| File | Description |
|---|---|
unified/ql/test/library-tests/local-name-binding/test.swift |
Adds two scoping regressions and reformats existing tests. |
unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll |
Updates parameter scopes, binding resolution, and scope-tree child handling. |
shared/namebinding/codeql/namebinding/LocalNameBinding.qll |
Moves name-and-scope matching to the common local-entity class. |
Review effort: Balanced (auto)
| ( | ||
| // Scope to the body so parameter defaults cannot see the parameter list | ||
| // TODO: Use a plugin for languages where parameter defaults can reference earlier parameters | ||
| scope = callable.getBody() |
Contributor
Author
There was a problem hiding this comment.
Pushing a test case to document this, but I'd like to leave it as-is.
AFAICT data flow will actually do the right thing (albeit mostly by accident), but this seems like too much of niche compared to how hard it is to fix, and the fix is unlikely to generalize to other languages where quirks like this are likely to behave differently.
hvitved
approved these changes
Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes two bugs:
LocalNameentity. This entity had multiple declaring callables resulting in consistency errors.Commit-by-commit review recommended.