realm / realm/SwiftLint

Autocorrect for `redundant_void_return` can cause code breakage

Open
#5,609 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

acceptable-false-positive bug
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

New Issue Checklist
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 version to 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.