Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to subclass NetworkDataResourceService broken in Swift 5.2 #84

Open
Jon889 opened this issue Feb 8, 2020 · 8 comments
Open

Comments

@Jon889
Copy link

Jon889 commented Feb 8, 2020

In Swift 5.2 there is a change that prevents changing the generic requirements in an overridden method. Which completely breaks our use of subclassing NetworkDataResourceService.

https://forums.swift.org/t/method-override-with-a-generic-signature-with-requirements-not-imposed-by-the-base-method/33593

Is there any ideas on how to resolve this?

@theblixguy
Copy link
Contributor

theblixguy commented Feb 8, 2020

I left a comment on your post with an explanation. Please let me know (on the forums) if you have any other questions about the change.

You can continue to use Swift 5.1 though.

@ahmedAlmasri
Copy link

I have the same issue any idea? +1

@theblixguy
Copy link
Contributor

Your options are:

  1. Stay on Swift 5.1.
  2. Perform a runtime cast (i.e. if let resource = resource as? SomeOtherResourceProtocol) to conditionally check the conformance (but it wont work if your protocol has Self or associatedtypes) and then do something.
  3. Change the design/architecture of your code.

@ahmedAlmasri
Copy link

I'm using a swift 5.1 but still, have a same issue , do can you see my code?

@theblixguy
Copy link
Contributor

To clarify, if you’re doing the above then the problem is with your code rather than the compiler. My suggestion to stay on Swift 5.1 is only temporary (while you investigate other approaches), the right way to fix the problem is to rewrite the code in a way that doesn’t break Liskov.

I implemented the changes in 5.2, so it’s not possible for the code to stop compiling in 5.1, so I assume you have a different but related problem? If you could show your code then I may be able to offer some suggestions.

@ahmedAlmasri
Copy link

ahmedAlmasri commented Mar 16, 2020

Thank you for replay

My question: https://stackoverflow.com/q/60710024/9315978

@theblixguy
Copy link
Contributor

Seems like some sort of alignment issue (at least in debug mode), in release mode it runs fine on Swift 5.1.

Anyway, it won't work on 5.2 because the code isn't correct. You're adding a new Decodable constraint when overriding responseBodyConverter but anyone can pass something that doesn't conform to Decodable via the base class's responseBodyConvertor down to the convert method, leading to a runtime crash.

@ahmedAlmasri
Copy link

@theblixguy thank you so much I fixed it using a check the types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants