Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-8268] Unexpected Invalid Redeclaration #50799

Closed
swift-ci opened this issue Jul 16, 2018 · 2 comments
Closed

[SR-8268] Unexpected Invalid Redeclaration #50799

swift-ci opened this issue Jul 16, 2018 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-8268
Radar rdar://problem/56835019
Original Reporter oge (JIRA User)
Type Bug
Status Resolved
Resolution Won't Do
Environment

Latest Mac update, Swift Version 4.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: df87332af6d8eeadda1968dc3c7be7d0

Issue Description:

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.

@belkadan
Copy link
Contributor

belkadan commented Nov 2, 2019

@swift-ci create

@slavapestov
Copy link
Member

We allow overloading functions on generic requirements, but the rules for non-function declarations like nested types and properties are more restrictive.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

3 participants