Skip to content

Commit

Permalink
[PoC] Modify materialize overload of Result<T, NSError> to be bui…
Browse files Browse the repository at this point in the history
…ldable on both Swift 3.0 and 3.1
  • Loading branch information
ikesyo committed Mar 1, 2017
1 parent 5db7bc7 commit 2588a09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@ matrix:
language: generic
install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
- script:
- docker run -v `pwd`:`pwd` -w `pwd` norionomura/swift:3120170205a swift test
env: JOB=Linux-Swift3.1
sudo: required
services: docker
notifications:
email: false
11 changes: 9 additions & 2 deletions Result/Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,15 @@ public func materialize<T>(_ f: () throws -> T) -> Result<T, NSError> {
public func materialize<T>(_ f: @autoclosure () throws -> T) -> Result<T, NSError> {
do {
return .success(try f())
} catch let error as NSError {
return .failure(error)
} catch {
#if _runtime(_ObjC)
return .failure(error as NSError)
#else
// https://github.com/apple/swift-corelibs-foundation/blob/swift-3.0.2-RELEASE/Foundation/NSError.swift#L314
let userInfo = _swift_Foundation_getErrorDefaultUserInfo(error) as? [String: Any]
let nsError = NSError(domain: error._domain, code: error._code, userInfo: userInfo)
return .failure(nsError)
#endif
}
}

Expand Down

0 comments on commit 2588a09

Please sign in to comment.