From 2588a09ef591f7d0aa07bffd0d8cdb3399be453a Mon Sep 17 00:00:00 2001 From: Syo Ikeda Date: Thu, 2 Mar 2017 07:21:46 +0900 Subject: [PATCH 1/3] [PoC] Modify `materialize` overload of `Result` to be buildable on both Swift 3.0 and 3.1 --- .travis.yml | 5 +++++ Result/Result.swift | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9a708b7..6509bc9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Result/Result.swift b/Result/Result.swift index 5dd14cd..0317d00 100644 --- a/Result/Result.swift +++ b/Result/Result.swift @@ -129,8 +129,15 @@ public func materialize(_ f: () throws -> T) -> Result { public func materialize(_ f: @autoclosure () throws -> T) -> Result { 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 } } From b26e95107a37ed57d0f2de98fc669dd048f1e649 Mon Sep 17 00:00:00 2001 From: Syo Ikeda Date: Fri, 3 Mar 2017 02:51:34 +0900 Subject: [PATCH 2/3] Use a recent 3.1-DEVELOPMENT-SNAPSHOT --- .travis.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6509bc9..17ee849 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,9 +30,15 @@ matrix: 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 + - swift build + - swift test + env: + - JOB=Linux + - SWIFT_VERSION=3.1-DEVELOPMENT-SNAPSHOT-2017-03-01-a sudo: required - services: docker + dist: trusty + language: generic + install: + - eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)" notifications: email: false From 939c0f360b1fa1ba2dc7ac87d395d77089d0ddf5 Mon Sep 17 00:00:00 2001 From: Syo Ikeda Date: Fri, 3 Mar 2017 02:56:16 +0900 Subject: [PATCH 3/3] Add a descriptive comment --- Result/Result.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Result/Result.swift b/Result/Result.swift index 0317d00..b08ea8e 100644 --- a/Result/Result.swift +++ b/Result/Result.swift @@ -130,6 +130,8 @@ public func materialize(_ f: @autoclosure () throws -> T) -> Result