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

[SR-6803] Accept same-file extensions for automatic synthesis of Equatable/Hashable #49352

Closed
NachoSoto opened this issue Jan 20, 2018 · 8 comments
Labels
compiler The Swift compiler in itself improvement type checker Area → compiler: Semantic analysis

Comments

@NachoSoto
Copy link
Contributor

Previous ID SR-6803
Radar rdar://problem/39199726
Original Reporter @NachoSoto
Type Improvement
Status Resolved
Resolution Done
Environment

Swift version 4.1-dev (LLVM ef53654946, Clang f7df1e5a04, Swift 831b78c)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, TypeChecker
Assignee None
Priority Medium

md5: 7ee094bf8b76b4c699a3948b5de96775

relates to:

  • SR-4920 Compiler crash when extending type with Codable

Issue Description:

Conditional conformance doesn't work well with automatic synthesis of Equatable/Hashable because the only way to define conformance is in extensions, but automatic synthesis isn't allowed there.

Consider:

struct A<T> {
  let t: T
}

extension A: Equatable where T: Equatable {}

Expected result:

Code compiles, and Equatable is synthesized

Actual result:

error: repl.swift:5:1: error: type 'A<T>' does not conform to protocol 'Equatable'
extension A: Equatable where T: Equatable {}

See https://twitter.com/dgregor79/status/954524765003292672.

@belkadan
Copy link
Contributor

@itaiferber, I know we had trouble doing this with Codable, but would your same work at least handle Equatable/Hashable? Maybe we can get that part in.

cc also @allevato

@itaiferber
Copy link
Contributor

@belkadan The issue wasn't Codable-specific — we'd run into the same problems with Equatable/Hashable. The problem is that

struct Foo { ... }
extension Foo : Equatable {}

hits code paths in the compiler in a different order from

extension Foo : Equatable {}
struct Foo { ... }

IIRC, the second form compiles but the first does not. We should try to figure out a way around this if we can; let's continue via email. I'll be back in the office tomorrow.

@NachoSoto
Copy link
Contributor Author

Are there plans to implement this for 4.1? I need to know whether I can count on these conditional conformances to be automatically synthesized.

@belkadan
Copy link
Contributor

belkadan commented Feb 2, 2018

It's unlikely, sorry.

@NachoSoto
Copy link
Contributor Author

So the 2 biggest features of Swift 4.1 won't actually work together 🙁

@huonw
Copy link
Mannequin

huonw mannequin commented Apr 5, 2018

@swift-ci create

@huonw
Copy link
Mannequin

huonw mannequin commented May 4, 2018

#16376

@huonw
Copy link
Mannequin

huonw mannequin commented May 7, 2018

90ba980

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself improvement type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants