Skip to content

Instantly share code, notes, and snippets.

@slavapestov
Last active October 6, 2017 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slavapestov/f455c6184b402f3ffc656f904f1e5d59 to your computer and use it in GitHub Desktop.
Save slavapestov/f455c6184b402f3ffc656f904f1e5d59 to your computer and use it in GitHub Desktop.
// Example 1
protocol P {
func f() -> Self
}
extension P {
func f() -> Self {
return self
}
}
class C : P {}
// Example 2
protocol Q {
associatedtype I = Self
func f() -> I
}
extension Q where Self.I == Self {
func f() -> Self {
return self
}
}
class D : Q {}
// Example 1 fails to type check in Swift 4.0.
// Example 2 works in Swift 4.0, but this doesn't work, which is counter-intuitive because E should inherit all members of D:
class E : D {}
E().f()
// b.swift:19:5: error: 'E' is not convertible to 'D'
// E().f()
// ~~~~^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment