Skip to content

Fix unused argument bug#2421

Merged
calda merged 3 commits intonicklockwood:developfrom
kimdv:kimdv/fix-unused-argument-bug
Feb 28, 2026
Merged

Fix unused argument bug#2421
calda merged 3 commits intonicklockwood:developfrom
kimdv:kimdv/fix-unused-argument-bug

Conversation

@kimdv
Copy link
Contributor

@kimdv kimdv commented Feb 27, 2026

While running develop branch (dc580e8) on out code base, we see this

        for item in items { <--- Before formatting
        for _ in items { <--- After formatting
            guard let item = try? await storage.record(
                matching: item.id
            ) else {
                return
            }

            storage.save(item)
        }

I added a test case to reproduce the error.

I will try to solve it, with Cursor, and maybe also I need to ask some stupid questions 😅

@kimdv kimdv changed the base branch from main to develop February 27, 2026 08:43
@kimdv
Copy link
Contributor Author

kimdv commented Feb 27, 2026

Analysis from Cursor:

Root cause: In isStartOfStatement (ParsingHelpers.swift), the .keyword("await") case checks if the previous token is a postfix operator and returns true (is a start of statement) if so. When parsing try? await, the ? after try is a postfix operator, so await was incorrectly treated as a new statement.

This caused removeUsed to call pushLocals() prematurely, moving the guard let binding (item) from tempLocals into locals. When the actual usage of item (in item.id) was later encountered, it was already in locals and skipped -- so the for-loop variable was never recognized as "used" and got replaced with _.

Fix: Added a new case in the switch inside isStartOfStatement for .operator("?", .postfix) and .operator("!", .postfix) that checks if the token before the operator is try or as. If so, the current token is a continuation of the expression, not a new statement, and false is returned. This mirrors an identical check that already existed for .identifier tokens (line 1159-1172) but was missing for .keyword("await").

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.29%. Comparing base (dc580e8) to head (2b79fa3).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2421      +/-   ##
===========================================
- Coverage    95.30%   95.29%   -0.01%     
===========================================
  Files          164      164              
  Lines        25080    25090      +10     
===========================================
+ Hits         23902    23910       +8     
- Misses        1178     1180       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@calda calda left a comment

Choose a reason for hiding this comment

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

Thanks!

@calda calda merged commit 0df1818 into nicklockwood:develop Feb 28, 2026
13 of 14 checks passed
@kimdv kimdv deleted the kimdv/fix-unused-argument-bug branch March 1, 2026 10:24
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