Skip to content

Remove DecodedType typealias (associatedtype) from Decodable protocol#100

Merged
ikesyo merged 9 commits into2.0-developmentfrom
remove-DecodedType
Mar 11, 2016
Merged

Remove DecodedType typealias (associatedtype) from Decodable protocol#100
ikesyo merged 9 commits into2.0-developmentfrom
remove-DecodedType

Conversation

@ikesyo
Copy link
Copy Markdown
Owner

@ikesyo ikesyo commented Mar 6, 2016

Addresses #97.

/cc @tarunon

@ikesyo ikesyo added this to the 2.0.0 milestone Mar 6, 2016
@ikesyo
Copy link
Copy Markdown
Owner Author

ikesyo commented Mar 6, 2016

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?

@tarunon
Copy link
Copy Markdown
Contributor

tarunon commented Mar 6, 2016

Yes, self.init(string: value)! is NSURL, not a Self.
I think we should cast NSURL to Self, but we cannot use Self in implement.
I have one idea, I'll make new pr. :3

@tarunon tarunon mentioned this pull request Mar 7, 2016
@ikesyo
Copy link
Copy Markdown
Owner Author

ikesyo commented Mar 7, 2016

Yes, self.init(string: value)! is NSURL, not a Self.
I think we should cast NSURL to Self, but we cannot use Self in implement.

I'm not sure why this succeeds on OS X with SwiftPM, but fails on Linux. 🤔

@tarunon
Copy link
Copy Markdown
Contributor

tarunon commented Mar 7, 2016

I don't know why... But I think Linux is correct.
Because if make NSURL subclass, cannot use self.init(string: String) without override.
It may be swift compiler bug.

@tarunon
Copy link
Copy Markdown
Contributor

tarunon commented Mar 7, 2016

Auk,

Yes, self.init(string: value)! is NSURL, not a Self.

I misunderstood this problem, sorry.
It is not necessary that Self has init(string: String) implement.

@ikesyo ikesyo force-pushed the remove-DecodedType branch from e1059c5 to c72a048 Compare March 7, 2016 10:58
@ikesyo ikesyo force-pushed the remove-DecodedType branch from 43fffb6 to 3d5634d Compare March 7, 2016 17:59

guard let result = rawValue as? T else {
throw typeMismatch("\(T.self)", actual: rawValue, keyPath: nil)
internal func castOrFail<T>(any: Any) throws -> T {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this arguments type must be Any?.
And we need a test of URLHolder decode success case.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this arguments type must be Any?.

Any can take Optional<Any>, so it would be fine, I think.

ikesyo added 3 commits March 9, 2016 13:56
Work arounds a test failure coming from the incompatibility of Optional's string representation between OS X and Linux.
@ikesyo ikesyo force-pushed the remove-DecodedType branch from 4bfccbc to dd8341f Compare March 9, 2016 10:49
@ikesyo ikesyo changed the title [WIP] Remove DecodedType typealias (associatedtype) from Decodable protocol Remove DecodedType typealias (associatedtype) from Decodable protocol Mar 9, 2016
@ikesyo
Copy link
Copy Markdown
Owner Author

ikesyo commented Mar 9, 2016

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that now.
OK, I have no idea about this pr. Thanks @ikesyo san. 😸

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tarunon I really appreciate your efforts on this! 👍 Many thanks 🙏

@ikesyo
Copy link
Copy Markdown
Owner Author

ikesyo commented Mar 11, 2016

Merging this 🚢

ikesyo added a commit that referenced this pull request Mar 11, 2016
Remove DecodedType typealias (associatedtype) from Decodable protocol
@ikesyo ikesyo merged commit 25b6a3d into 2.0-development Mar 11, 2016
@ikesyo ikesyo deleted the remove-DecodedType branch March 11, 2016 04:38
@ikesyo ikesyo mentioned this pull request Apr 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants