Stop unused_parameter flagging $-prefixed closure parameters - #6763
Closed
systemblueio wants to merge 1 commit into
Closed
systemblueio wants to merge 1 commit into
systemblueio wants to merge 1 commit into
Conversation
Generated by 🚫 Danger |
2 tasks
A closure parameter written as a property-wrapper projection (e.g.
`list($items) { $item in ... }`) also binds the wrapped value `item`,
which can be referenced without the `$` prefix. The rule could not see
that implicit binding, so it reported the parameter as unused and its
autocorrect produced invalid Swift (`{ $item _ in }`).
Skip `$`-prefixed parameters in the violation check, mirroring the
existing underscore handling. `$`-prefixed names only occur as closure
projections, so regular parameters are unaffected.
Resolves #5740.
Co-Authored-By: Claude <noreply@anthropic.com>
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 #5740.
Problem
unused_parameterflagged$-prefixed closure parameters as unused:A closure parameter written as a property-wrapper projection (
$item) alsobinds the wrapped value
item, which is referenced here without the prefix.The rule only tracked the
$itemspelling, so it reported the parameter asunused, and its autocorrect rewrote the closure to invalid Swift:
list($items) { $item _ in ... }.Fix
Skip
$-prefixed parameters in the violation check, mirroring the existingunderscore handling.
$-prefixed names only occur as closure projections, sofunction, initializer, and subscript parameters are unaffected, and genuinely
unused regular closure parameters are still reported.
Tests
Added two non-triggering examples (wrapped value used, projected value used).
UnusedParameterRuleGeneratedTestspasses, and the built binary no longerreports the issue's example while still flagging a plain unused closure
parameter.