Created
June 10, 2019 20:32
-
-
Save r-peck/bc9fff0d54e3beea77d3beb0654bed0c to your computer and use it in GitHub Desktop.
Inferring nested associated types with opaque return types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol A { } | |
struct AImpl: A { | |
init() { } | |
} | |
protocol B { | |
associatedtype BA: A | |
var a: BA { get } | |
} | |
struct BImpl: B { | |
init() { } | |
var a: some A { | |
return AImpl() | |
} | |
} | |
protocol C: B { | |
associatedtype CB: B where BA == CB.BA | |
var b: CB { get } | |
} | |
extension C { | |
var a: BA { | |
return b.a | |
} | |
} | |
struct CImpl: C { // Type 'CImpl' does not conform to protocol 'B', wants to insert typealias for BA | |
var b: some B { | |
return BImpl() | |
} | |
} | |
//struct CImpl: C { // 'C' requires the types 'CImpl.BA' (aka 'some A') and '(some B).BA' to be equivalent | |
// typealias BA = BImpl.BA | |
// | |
// var b: some B { | |
// return BImpl() | |
// } | |
//} | |
//struct CImpl: C { // Works but requires being explicit with types | |
// typealias BA = BImpl.BA | |
// | |
// var b: BImpl { | |
// return BImpl() | |
// } | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment