Swift does not compile the following code because B is declared twice
struct Identity<A> {
let a: A
}
extension Identity where A == Int {
// Invalid redeclaration of 'B'
enum B {}
}
extension Identity where A == String {
// Invalid redeclaration of 'B'
enum B {}
}
However, if I change the block to
struct Identity<A> {
let a: A
}
extension Identity where A == Int {
enum B {}
}
// 'Identity<String>.B' requires the types 'String' and 'Int' be equivalent
Identity<String>.B
This second block should fail to compile (according to my brain). However, the first one should be fine. Is this issue a bug? Is there anyway around these issues without renaming B?
That's what caused my initial confusion. When dealing with generic types I often have an extension like so
extension Identity<A> where A == Int {
static var production: Int { someExpensiveComputationInt() }
static var test: Int { 42 }
}
extension Identity<A> where A == String {
static var production: String { someExpensiveComputationString() }
static var test: String { "forty two" }
}
This seems like an appropriate topic to raise over in #evolution:discuss, where you may get a bit more attention from people who can definitively answer questions about the technical feasibility of this feature!