Thomvis / BrightFutures

Write great asynchronous code in Swift using futures and promises
MIT License
1.9k stars 184 forks source link

Reduce "warning: will never be executed" #218

Closed paiv closed 3 years ago

paiv commented 3 years ago
% swift -version
Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)
Target: x86_64-apple-darwin20.4.0
% swift build
BrightFutures/Sources/BrightFutures/AsyncType+ResultType.swift:233:54: warning: will never be executed
        return mapError(ImmediateExecutionContext) { $0 as! E } // future will never fail, so this map block will never get called
                                                     ^
BrightFutures/Sources/BrightFutures/AsyncType+ResultType.swift:233:52: note: '$0' is uninhabited, so this function body can never be executed
        return mapError(ImmediateExecutionContext) { $0 as! E } // future will never fail, so this map block will never get called
                                                   ^
BrightFutures/Sources/BrightFutures/AsyncType+ResultType.swift:265:49: warning: will never be executed
        return map(ImmediateExecutionContext) { $0 as! T } // future will never succeed, so this map block will never get called
                                                ^
BrightFutures/Sources/BrightFutures/AsyncType+ResultType.swift:265:47: note: '$0' is uninhabited, so this function body can never be executed
        return map(ImmediateExecutionContext) { $0 as! T } // future will never succeed, so this map block will never get called
                                              ^
BrightFutures/Sources/BrightFutures/AsyncType+ResultType.swift:233:54: warning: will never be executed
        return mapError(ImmediateExecutionContext) { $0 as! E } // future will never fail, so this map block will never get called
                                                     ^
BrightFutures/Sources/BrightFutures/AsyncType+ResultType.swift:233:52: note: '$0' is uninhabited, so this function body can never be executed
        return mapError(ImmediateExecutionContext) { $0 as! E } // future will never fail, so this map block will never get called
                                                   ^
BrightFutures/Sources/BrightFutures/AsyncType+ResultType.swift:265:49: warning: will never be executed
        return map(ImmediateExecutionContext) { $0 as! T } // future will never succeed, so this map block will never get called
                                                ^
BrightFutures/Sources/BrightFutures/AsyncType+ResultType.swift:265:47: note: '$0' is uninhabited, so this function body can never be executed
        return map(ImmediateExecutionContext) { $0 as! T } // future will never succeed, so this map block will never get called
                                              ^
[17/17] Merging module BrightFutures

There is no way in Swift to suppress a warning on a line of code. This patch is not as clean as original functional code, but the warnings go away.

Thomvis commented 3 years ago

Thanks for the PR. 👏 I've merged it into master and took the liberty to revise your implementation slightly.