You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
unneeded_throws_rethrows false positive when try is in parameter in a function with trailing closure #6491
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.
importFoundationfunca()throws->String{throwNSError(domain:"a",code:1,userInfo:nil)}funcb(text:String,completion:()->Void){print(text)completion()}funcc()throws{ // Violation on the throw here
b(text:trya()){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 handled14 | print("")15 | }
Without the closure, no violation is reported:
importFoundationfunca()throws->String{throwNSError(domain:"a",code:1,userInfo:nil)}funcb(text:String){print(text)}funcc()throws{ // All good
b(text:trya())}
$ 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 functiondoes 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
Activity
Nef10 commentedon Feb 14, 2026
@SimplyDanny wow you are so fast, thank you very much!