Skip to content

unneeded_throws_rethrows false positive when try is in parameter in a function with trailing closure #6491

Closed

Description

@Nef10

New Issue Checklist

Bug Description

A clear and concise description of what the bug is. Ideally, provide a small (but compilable) example code snippet that
can be used to reproduce the issue.

import Foundation

func a() throws -> String {
    throw NSError(domain: "a", code: 1, userInfo: nil)
}

func b(text: String, completion: () -> Void) {
    print(text)
    completion()
}

func c() throws { // Violation on the throw here
    b(text: try a()) {
        print("")
    }
}

However, it is required by the compiler. Without the throw:

$ swift a.swift                                                           
a.swift:13:13: error: errors thrown from here are not handled
11 | 
12 | func c() {
13 |     b(text: try a()) {
   |             `- error: errors thrown from here are not handled
14 |         print("")
15 |     }

Without the closure, no violation is reported:

import Foundation

func a() throws -> String {
    throw NSError(domain: "a", code: 1, userInfo: nil)
}

func b(text: String) {
    print(text)
}

func c() throws { // All good
    b(text: try a())
}
$ swiftlint lint --only-rule unneeded_throws_rethrows --no-cache ./a.swift
Linting Swift files at paths ./a.swift
Linting 'a.swift' (1/1)
/Users/steffen/Desktop/a.swift:12:10: warning: Unneeded (Re)Throws Keyword Violation: Superfluous 'throws'; body of this function does not throw any error (unneeded_throws_rethrows)
Done linting! Found 1 violation, 0 serious in 1 file.

Environment

  • SwiftLint version (run swiftlint version to be sure) 0.63.2
  • Xcode version (run xcodebuild -version to be sure) Xcode 26.2 Build version 17C52
  • Installation method used (Homebrew, CocoaPods, building from source, etc) Homebrew
  • Are you using nested configurations? No

Activity

  1. added
    bug
    on Feb 13, 2026
  2. self-assigned this
    on Feb 13, 2026
  3. Nef10 commented on Feb 14, 2026

    @Nef10
    Author

    @SimplyDanny wow you are so fast, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions