Autocorrect for `redundant_void_return` can cause code breakage
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
Describe the bug
After upgrading to SwiftLint to 0.55.1 code like this (below) breaks when applying --fix. Reverting to version 0.53.0 makes it work. I found some easy workarounds but I don't think it's good to break existing code.
Complete output when running SwiftLint, including the stack trace and command used
main.swift
func takesClosure(_ closure: () -> Void) { }
@discardableResult func returnsInt() -> Int { 42 }
let testClosure = { () -> Void in returnsInt() }
takesClosure(testClosure)
This code works but after swiftlint --fix, swift main.swift causes error:
main.swift:7:14: error: cannot convert value of type '() -> Int' to expected argument type '() -> Void'
Environment
-
SwiftLint version (run
swiftlint versionto be sure)? 0.55.1. -
Installation method used (Homebrew, CocoaPods, building from source, etc)? Homebrew.
-
Paste your configuration file: n/a.
-
Are you using nested configurations? No.
-
Which Xcode version are you using (check
xcodebuild -version)? 15.4. -
Do you have a sample that shows the issue? Yes, above.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the main.swift reproduction and run SwiftLint 0.55.1 with --fix, then compare the result with SwiftLint 0.53.0. Trace the redundant_void_return autocorrection and verify that the corrected closure still runs with swift main.swift and can be passed to takesClosure without a type error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100