Skip to content

Respect scope qualifiers when resolving local functions - #16

Merged
jessehouwing merged 2 commits into
jessehouwing:mainfrom
PrzemyslawKlys:fix/scoped-local-function-resolution
Oct 8, 2026
Merged

jessehouwing merged 2 commits into
jessehouwing:mainfrom
PrzemyslawKlys:fix/scoped-local-function-resolution

Conversation

@PrzemyslawKlys

Copy link
Copy Markdown

PR Summary

Scoped function declarations currently fall back to the installed command's metadata. For example, PSUseCorrectCasing suggests Path for this call even though the function declares PATH:

function script:Get-ChildItem { param($PATH) }
Get-ChildItem -PATH 'x'

This uses the existing function-name normalizer for the four supported scope prefixes and preserves their visibility: local declarations stay in their containing scope, private declarations stay in their exact defining scope, and script/global declarations remain visible across the script. Directly invoked child blocks are distinguished from dot-sourced blocks and scriptblock arguments. Module-qualified cmdlet calls still resolve against the module.

The dot-source collector also excludes ordinary local/private definitions nested in a child scope. It previously flattened those definitions into the file group and could hide a legitimate diagnostic in another file. Scoped declarations that are visible in the shared scope still reach the other dot-sourced files.

This targets your branch for PowerShell/PSScriptAnalyzer#2206, based on 3f5bf19. It is independent of the suppression-scan contribution in #15. No public API, dependency or execution-order model is added; this remains conservative static command resolution.

Native net8 and net462 builds passed. The selected engine, casing and formatter suites passed 82 tests on both PowerShell 7.6.6 and Windows PowerShell 5.1, with two existing skips. All 25 new cases run; the unchanged baseline fails 22 of them. Seven isolated runtime probes confirm scope behavior on both hosts. Validation covers analyzer and formatter output, mandatory-parameter lookups, private child-scope boundaries, dot-source groups, unrelated cmdlets and analysis isolation.

Final comparisons preserve the formatted bytes and complete diagnostic details for Locksmith (244 diagnostics), PSSharedGoods (308) and PSWriteHTML (857), with no rule errors. An independent review and targeted confirmation covered the scope boundaries and dot-source filtering.

PR Checklist

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants