Skip to content

Instantly share code, notes, and snippets.

@mikeash
Created May 8, 2018 14:21
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 mikeash/46761b525de8a4c23e4a542585818c62 to your computer and use it in GitHub Desktop.
Save mikeash/46761b525de8a4c23e4a542585818c62 to your computer and use it in GitHub Desktop.
class C {}
protocol P where Self: C {
var x: Int { get }
var y: Int { get }
}
extension P {
var x: Int { return 42 }
}
class D: C, P {
var y: Int { return x + 1 }
}
func f(vc: C) {
if let vc = vc as? P {
print(vc.x)
print(vc.y)
}
}
f(vc: D())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment