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-13141] Type does not conform to protocol #55588

Closed
swift-ci opened this issue Jul 4, 2020 · 4 comments
Closed

[SR-13141] Type does not conform to protocol #55588

swift-ci opened this issue Jul 4, 2020 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 4, 2020

Previous ID SR-13141
Radar rdar://problem/65115994
Original Reporter TheFishingRod (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift 5

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

md5: d6ea6efcc5cf58bd5d9a6d40ae80d859

Issue Description:

Code:

protocol Book {
    associatedtype Name
} 
protocol BookDecorator: Book where Name == DecoratedBook.Name {
    associatedtype DecoratedBook: Book
    associatedtype Name = DecoratedBook.Name
}  
class ConcreteBookDecorator<T: Book>: BookDecorator {
    typealias DecoratedBook = T
}

This simple example will reproduce an error:

"Type 'ConcreteBookDecorator<T>' does not conform to protocol 'BookDecorator'"

Remove the where clause and the error will be gone.

@typesanitizer
Copy link

I don't understand. The first thing that is needed to conform to BookDecorator is a conformance to Book. Why not add the conformance to Book? The extra Name in BookDecorator is redundant, since the where clause for BookDecorator guarantees that Name == DecoratedBook.Name.

protocol Book {
  associatedtype Name
}
protocol BookDecorator: Book where Name == DecoratedBook.Name {
  associatedtype DecoratedBook
}
class ConcreteBookDecorator<T: Book>: Book, BookDecorator {
  typealias Book = T.Name
  typealias DecoratedBook = T
}

@typesanitizer
Copy link

I take that back. Apparently, we do support just writing the last protocol in the chain directly. I suppose the question really is: why can't the associated type be inferred? Oh well.

@typesanitizer
Copy link

@swift-ci create

@slavapestov
Copy link
Member

This is now working on master. I added a regression test - #33549

@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
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants