Comments (3)
cc @slavapestov
from swift.
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.
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)
- Unexpected "copy of noncopyable typed value" error.
- Macro in global is not working
- swift_getSingletonMetadata crashes when called via Bundle.main.classNamed()
- `ClangImporter/SceneKit_test.swift` fails on clean checkout HOT 1
- Bad diagnostic for `any P!` HOT 3
- Update CONTRIBUTING.md to include PR process / forking information HOT 1
- using isKnownUniquelyReferenced seems to crash on C++ reference type HOT 2
- No `any` syntax migration error for protocol qualifier
- Compiler crash with circular reference, redundant conformance requirements
- Incorrect absoluteString for URL on linux HOT 1
- Incorrect 'class inherits from itself'
- Assertion failure: `extReqs.size() == typeReqs.size())` in `isWrittenWithConstraints`. HOT 1
- `import typealias` causes invalid error claiming the symbol is a protocol
- No literal initialization via coercion in generic code :(
- Wrong Sendable closure diagnostics with implicitly unwrapped optional HOT 1
- Compiler crashed: Referring os.Logger instance in custom constructor of String
- cloning swift fails HOT 1
- Unable to use std::chrono clocks via Cxx interop
- Compiler crash with generic result builders
- `@discardableResult` doesn't work with computed property getter
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift.