Remove DecodedType typealias (associatedtype) from Decodable protocol#100
Remove DecodedType typealias (associatedtype) from Decodable protocol#100ikesyo merged 9 commits into2.0-developmentfrom
Conversation
|
The build failed on Linux with the following error: $ swift test
Compiling Swift Module 'Himotokitest' (6 sources)
/home/travis/build/ikesyo/Himotoki/Tests/Himotoki/DecodeErrorTest.swift:25:21: error: constructing an object of class type 'Self' with a metatype value must use a 'required' initializer
return self.init(string: value)!
~~~~ ^
Foundation.NSURL:15:24: note: selected non-required initializer 'init(string:)'
public convenience init?(string URLString: String)
^
<unknown>:0: error: build had 1 command failures
error: exit(1): swift-build-tool -f /home/travis/build/ikesyo/Himotoki/.build/debug.yaml test@tarunon Do you have any solution or workaround for this? |
|
Yes, |
I'm not sure why this succeeds on OS X with SwiftPM, but fails on Linux. 🤔 |
|
I don't know why... But I think Linux is correct. |
|
Auk,
I misunderstood this problem, sorry. |
e1059c5 to
c72a048
Compare
43fffb6 to
3d5634d
Compare
Sources/StandardLib.swift
Outdated
|
|
||
| guard let result = rawValue as? T else { | ||
| throw typeMismatch("\(T.self)", actual: rawValue, keyPath: nil) | ||
| internal func castOrFail<T>(any: Any) throws -> T { |
There was a problem hiding this comment.
I think this arguments type must be Any?.
And we need a test of URLHolder decode success case.
There was a problem hiding this comment.
I think this arguments type must be
Any?.
Any can take Optional<Any>, so it would be fine, I think.
Work arounds a test failure coming from the incompatibility of Optional's string representation between OS X and Linux.
4bfccbc to
dd8341f
Compare
|
Okay, this should be good to go now. @tarunon Do you have further thoughts on this? |
|
|
||
| guard let result = rawValue as? T else { | ||
| throw typeMismatch("\(T.self)", actual: rawValue, keyPath: nil) | ||
| internal func castOrFail<T>(any: Any?) throws -> T { |
There was a problem hiding this comment.
func castOrFail<T>(any: Any?) throws -> T is convenient function in Decodable, so I would like to it to public function, I think.
Or, adding Decodable extension is good for this.
There was a problem hiding this comment.
I'm not sure what the real world use case is. The users can implement Decodable.decode(e: Extractor) by using required initializer or also can use Transformer API for decoding non-final classes. Honestly I'm not willing to make it public.
There was a problem hiding this comment.
I understand that now.
OK, I have no idea about this pr. Thanks @ikesyo san. 😸
There was a problem hiding this comment.
@tarunon I really appreciate your efforts on this! 👍 Many thanks 🙏
|
Merging this 🚢 |
Remove DecodedType typealias (associatedtype) from Decodable protocol
Addresses #97.
/cc @tarunon