Giter VIP home page Giter VIP logo

Comments (3)

xedin avatar xedin commented on June 3, 2024

cc @slavapestov

from swift.

slavapestov avatar slavapestov commented on June 3, 2024

Normally when you declare a conditional conformance you must explicitly declare the conformance to the inherited protocol, eg if you wanted your S to be Hashable you'd want to write something like this:

struct S<T> {}

extension S: Equatable where T: Equatable {}
extension S: Hashable where T: Hashable {}

This is because carrying over the bound to the inherited protocol (extension S: Equatable where T: Hashable) would be wrong.

However, an exception was made for Sendable to avoid breaking existing code; if some existing protocol is changed to inherit Sendable, and you conform to it conditionally, you get an implied Sendable conformance with the same conditional requirements.

You found the case where this rule doesn't work (which is why we don't want it in general, it's a backwards compatibility hack).

You can get around this by explicitly stating an unconditional Sendable conformance. The below type checks correctly for me:

protocol A: Sendable { }
protocol B: Sendable { }
struct S<T> { }
extension S: Sendable { }
extension S: A where T: A { }
extension S: B where T: B { }

from swift.

groue avatar groue commented on June 3, 2024

Normally when you declare a conditional conformance you must explicitly declare the conformance to the inherited protocol

🤦‍♂️ How did I forget that? I was too much focused on the "no breaking change" and slightly mislead by diagnostic messages. I should have mentioned this in my report.

However, an exception was made for Sendable to avoid breaking existing code.

Thank you for restating what Holly was saying in the forums.

You found the case where this rule doesn't work (which is why we don't want it in general, it's a backwards compatibility hack).

I very much welcome the intent, because it lets me do my job of OSS maintainer obsessed with backward compatibility :-) This also looks like a hack, but I was so relieved to see it.

You can get around this by explicitly stating an unconditional Sendable conformance.

Great 👍 This reduces the severity of the issue (for my own use case): if the issue still exists when Xcode 15.3 ships, I'll just mention the workaround in my documentation and guide users towards a solution.

Thank you very much @slavapestov!

from swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.