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
[SR-10187] Encodable Extension never finishes compiling #52589
Comments
We get a "nice" "crash" on master:
|
Crashing for me on near-master: bad base type
UNREACHABLE executed at /Users/suyashsrijan/Documents/swift-src/swift/lib/AST/Type.cpp:3191! I think the issue here is we're trying to synthesise Encodable conformance for a class which does not have an initialiser? We do end up emitting a diagnostic but then start solving the constraints... I'll assign this to myself. |
Also noticed that changing "CodingKeys" to something else does not lead to the crash... interesting! This does not crash:
class Foo<T: Equatable> {
private let bar: String
}
extension Foo: Encodable where T: Encodable {
enum CodingKeys1: CodingKey {
case bar
}
} Maybe there is some sort of conflict with the synthesised `CodingKeys` |
After a bit of digging, the problem is basically that this (and this seems to be limited to a constrained extension case like above, I couldn't reproduce it otherwise) - normally, the compiler will synthesise CodingKeys on the parent type in such a case (if you name the CodingKeys in the above extension something else, like "CodingKeys1"). However, in this case, the compiler isn't doing that because the one on the extension is called "CodingKeys". The fix for it is we reject it but synthesise a CodingKeys enum on the parent type. This mimics the behaviour of the compiler when the enum isn't called "CodingKeys". |
That's not right. If the user manually writes a CodingKeys, Codable synthesis is supposed to use it. |
Thank you @theblixguy! This has indeed been fixed by my PR (I've also cherry-picked in to 5.1 branch). |
Environment
Xcode 10.2, Swift 4.2
Additional Detail from JIRA
md5: 05ca6c84f18b7dd9ab600f4db3d9b2c8
Issue Description:
Attached code blocks the compiler from ever finishing.
Test case:
The text was updated successfully, but these errors were encountered: