Swiftformat: Return removed catch let block

Created on 20 Oct 2019  路  5Comments  路  Source: nicklockwood/SwiftFormat

Similar to a couple other resolved issues, e.g. #346

redundantReturn is removing removing return from a catch let block

Before swiftformat:

do {
  ...     
} catch let e as DecodingError {
    return .failure(.decodingError(e))
} catch {
    return .failure(.error(error))
}

After swiftformat:

do {
  ...     
} catch let e as DecodingError {
    .failure(.decodingError(e))
} catch {
    return .failure(.error(error))
}

Using // swiftformat:disable:next redundantReturn for now as suggested in other issues :)

Thanks for your awesome work!

Most helpful comment

@ryanmeisters thanks for reporting this, I'll get it fixed asap.

All 5 comments

@ryanmeisters thanks for reporting this, I'll get it fixed asap.

@ryanmeisters I wasn't able to reproduce this with the information provided. I suspect it may depend on the surrounding code. Can you provide an isolated sample that demonstrates the issue?

Oh hmm. Sure thing. I'm able to reproduce with the following

func test() -> Int {
  do {
    let x = try JSONDecoder().decode(String.self, from: Data())
    return 1
  } catch let e as DecodingError {
    return 1 // <-- swiftformat removes return here
  } catch {
    return 1
  }
}

Just in case, here is my actual code
and here is my .swiftformat

I was being stupid and not setting the swift version to >=5.1 馃お I've got a solution now, and it'll be fixed in the next release. Thanks again 馃憤

@ryanmeisters fixed in 0.40.14.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DagAgren picture DagAgren  路  4Comments

Cyberbeni picture Cyberbeni  路  4Comments

PompeiaPaetenari picture PompeiaPaetenari  路  4Comments

DavinAhn picture DavinAhn  路  4Comments

AniHovhannisyanAni picture AniHovhannisyanAni  路  3Comments