[swift-evolution] [Idea] Add forced conversion for Error catching pattern matching
Michel Fortin
michel.fortin at michelf.ca
Mon Mar 21 20:20:27 CDT 2016
Le 20 mars 2016 à 16:26, Tyler Fleming Cloutier via swift-evolution <swift-evolution at swift.org> a écrit :
>
> Would it be wise to allow force conversion for the cases in which the developer believes the match is exhaustive? ie
>
> do {
> let action = chooseAction(game)
> game = try game.applyAction(action)
> } catch let e as ActionError {
> game.failedAction = e
> } catch _ {
> fatalError(“This is an unfortunate bit of noise :/")
> }
>
> becomes
>
> do {
> let action = chooseAction(game)
> game = try game.applyAction(action)
> } catch let e as! ActionError {
> game.failedAction = e
> }
If you move the cast on the next line it'll compile and do what you want with exactly the same amount of code:
do {
let action = chooseAction(game)
game = try game.applyAction(action)
} catch let e {
game.failedAction = e as! ActionError
}
--
Michel Fortin
https://michelf.ca
More information about the swift-evolution
mailing list