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-10634] Extension on final class in separate Framework causes name collision #53034

Closed
swift-ci opened this issue May 7, 2019 · 2 comments
Assignees
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

swift-ci commented May 7, 2019

Previous ID SR-10634
Radar https://bugreport.apple.com/web/?problemID=50538534
Original Reporter ezamagni (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 10.2.1 (10E1001)

Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Miscompile
Assignee @eeckstein
Priority Medium

md5: 7cb164b590d6e8801052dedae5b2f66c

Issue Description:

Given the following class definitions in which two final classes with the same name are declared inside different structs but both inherit from a base class:

open class Base {  ...  }

public struct StructA {
    final public class Homonym: Base {  ... }
}

public struct StructB {
    final public class Homonym: Base { ... }
}

When i declare the following extension in a separate project that links with said framework:

extension StructA.Homonym { 
    convenience init() { ... } 
}

and then i use the convenience init to initialize a StructA.Homonym:

let homonym = StructA.Homonym()

the compiler erroneously creates an object of type StructB.Homonym!

(lldb) po type(of: homonym)
Homonyms.StructB.Homonym

hence the extension seems to be applied to StructB.Homonym instead of StructA.Homonym.

Please run the attached workspace to see the strange behaviour.

Please note that this seems to happen only if the class hierarchy is declared in a separate framework: this behaviour does not seem to be reproducible inside a playground. If the classes are not declared as final, the application behaves as expected. If the extension is declared (as public) inside the framework, the application behaves as expected.

@belkadan
Copy link
Contributor

belkadan commented May 7, 2019

Reproduced. Very scary, thanks for the minimized test case!

@eeckstein
Copy link
Member

fixed in #24705

@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