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-5392] Inconsistent "invalid redeclaration of typealias" #47966

Open
jepers opened this issue Jul 7, 2017 · 3 comments
Open

[SR-5392] Inconsistent "invalid redeclaration of typealias" #47966

jepers opened this issue Jul 7, 2017 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@jepers
Copy link

jepers commented Jul 7, 2017

Previous ID SR-5392
Radar None
Original Reporter @jepers
Type Bug
Environment

Xcode 9 beta 2, tried both default toolchain and dev snapshot 2017-06-03

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

md5: fa37b4ccfbea6b9fbc48f07ee361235d

relates to:

  • SR-7217 Protocol composition with conflicting typealiases does not diagnose
  • SR-3793 Protocol extension cannot implement associated type
  • SR-5440 Typealias in constrained extension misinterprets the where clause

Issue Description:

protocol P {
    associatedtype A
    typealias B = Int
}
extension P where A == Bool {
    typealias B = Float // Compiles, but should it?
}
extension P where A == Double {
    typealias B = String // ERROR: Invalid redeclaration of `B`
}
// Note that Bool, Int, Float, Double and String can be any types; ie
// the topmost extension will always compile and the rest will not.
// Same behavior with generic typealiases.
// Should both compile (thus shadowing the default B) or should both be
// considered redeclarations?
// The same example but with a struct instead of a protocol consistently
// treats both as redeclarations:
struct S<A> {
    typealias B = Int
}
extension S where A == Bool {
    typealias B = Float // ERROR: Invalid redeclaration of `B`
}
extension S where A == Double {
    typealias B = String // ERROR: Invalid redeclaration of `B`
}
@jepers
Copy link
Author

jepers commented Apr 14, 2019

This bug is still (after almost two years) not fixed. Tested Xcode 10.2 default toolchain and the latest dev snapshot (2019-04-10).

@swift-ci
Copy link
Collaborator

Comment by Valentyn Zakharenko (JIRA)

The typealias B existence in the protocol P declaration isn't necessary to reproduce this defect. I mean that the behavior is the same for the following declaration.

protocol P {
    associatedtype A
    // typealias B = Int
}

@swift-ci
Copy link
Collaborator

Comment by Valentyn Zakharenko (JIRA)

The most painful case is when you need to create two different extensions to confirm two different protocols that have associatedtype-s with the same name, and those protocols are in a third-party framework. To do it you should reimplement half of the project instead of use extension that exists especially to provide the ability to extend the program so easy. At this moment you think: Why didn't I build my system with classes based on OOP? Why did I use extensions?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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

2 participants