[SR-522] Protocol funcs cannot have covariant returns #43139
Labels
compiler
The Swift compiler in itself
conformances
Feature → protocol: protocol conformances
feature
A feature request or implementation
improvement
protocol
Feature → type declarations: Protocol declarations
type checker
Area → compiler: Semantic analysis
Attachment: Download
Environment
Xcode 7.2
Additional Detail from JIRA
md5: 25aabb7ea4b4c8e107945dc27bb41814
is duplicated by:
relates to:
Issue Description:
Currently Swift is inconsistent on how it handles covariant return types, consider the code below:
The behaviour is odd in that if a class overrides a method from another class then covariant return types are allowed. However if a class or struct implements a method from a protocol then it can't implement with a covariant return type.
When you implement a method with a protocol extension you get similar behaviour in that a class that overrides the already implemented behaviour can now have a covariant return type:
Chris Lattner on swift-evolution suggested that this is a bug and in all cases covariant return types should be allowed.
Above code in attached project.
The text was updated successfully, but these errors were encountered: