You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PowerShell: branch counts [switch] types, -not and ForEach-Object (precision 0.86); closures counts every { } block (precision 0.18) #8903
Two PowerShell families count things that are not what the contract names. Found by the keyword-family validity tool (#8864) with a PowerShell oracle, on the PowerShell repository's test/powershell (676 functions matched):
branch fires where there is no decision (recall 1.00, precision 0.86; all 31 false-positive functions contain one of these):
the word switch inside a parameter type, [switch]$s (read as a switch statement);
-not, a unary negation, which is not a choice between paths (-and/-or/-xor are binary short-circuit-like operators and are a separate question, see the boolean-operator issue);
ForEach-Object, matched on its ForEach (an iteration cmdlet in a pipeline, which the contract files under comprehensions: "a map/filter/fold/for-each call", not under branch).
closures counts every { } block, so every function body is a "closure" (precision 0.18). The rule (powershell.py, "closures": re.compile(r"\{\s{0,20}(?:param\s{0,10}\([^)]{0,300}\))?[^}]{0,500}\}", re.I)) matches any braced block, not a scriptblock literal used as a value (the contract: "the syntax that opens an anonymous callable ... at the point it is defined").
Reproduce (scanned with the pinned scanner; counts read from function_data)
functionps_switch_type { param([switch]$s) 1 } # struct_branch == 1, should be 0functionps_not { param($x) return-not$x } # struct_branch == 1, should be 0functionps_foreach_obj { 1|ForEach-Object { $_ } } # struct_branch == 1 (a loop cmdlet: comprehensions, not branch)functionps_write_output { Write-Output1 } # struct_closures == 1, should be 0 (no scriptblock literal anywhere)
Expected
branch counts switch as a statement, not as a type in [switch]; does not count -not; and either counts ForEach-Object and Where-Object consistently (as loops) or leaves them to comprehensions. closures counts a scriptblock { ... } only where it is a value (an argument, an assignment or a pipeline stage), not the body of function name { }.
Note: the branch contract (docs/branch_rule_contract.md) records that break and continue still sit in PowerShell's branch rule (a deferred relocation, #2832); this issue is about the cases above only.
Part of #8863. Time the change (CPU seconds on keyword-rosetta and language-crucible); rosetta:rebless-owed if counts move; add each case above as a test.
Claimed by promoter-bot host melek, lease renewed 2026-11-23T12:11Z. It lapses after 6 h without a renewal. To take it back, assign someone or remove the claim:melek label.
Activity
squid-protocol commentedon Nov 22, 2026
Claimed by promoter-bot host
melek, lease renewed 2026-11-23T12:11Z. It lapses after 6 h without a renewal. To take it back, assign someone or remove theclaim:meleklabel.squid-protocol commentedon Nov 23, 2026
Fixed by #9111 (merged as fcc440b), which carried this issue's PR (rebuilt with eight others to re-bless the golden snapshots once).