I was exploring some things with the swift language and came across this example:
// Swift Version: 4.1
// ------ Example 1 ---- // No invalid redeclaration error
// I expected this
protocol VersionedProtocol {
associatedtype Version : VersionType
}
protocol VersionType {}
enum Version0x0x0 : VersionType {}
enum Version0x0x1: VersionType {}
extension VersionedProtocol where Version == Version0x0x0 {
func foo() {}
}
extension VersionedProtocol where Version == Version0x0x1 {
func foo() {}
}
// ---- Example 2 ----- // invalid redeclaration Foo
// I did not expect this
protocol VersionedProtocol {
associatedtype Version : VersionType
}
protocol VersionType {}
enum Version0x0x0 : VersionType {}
enum Version0x0x1: VersionType {}
extension VersionedProtocol where Version == Version0x0x0 {
typealias Foo = Int
}
extension VersionedProtocol where Version == Version0x0x1 {
typealias Foo = String
}
// I expected the errors in 3 and 4
// ---- Example 3 ----- // invalid redeclaration foo()
func foo() {}
func foo() {}
// ---- Example 4 ---- // invalid redeclaration Foo
typealias Foo = Int
typealias Foo = String
In example 3 and 4, I expect invalid redeclaration (specifically: invalid redeclaration foo() and invalid redeclaration Foo respectively), that makes sense to me. But why don't I get an invalid redeclaration in example 1 if I get an invalid redeclaration in example 2.