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-3228] Compiler allows overriding functionality of classes included from frameworks via extensions #45816

Closed
swift-ci opened this issue Nov 17, 2016 · 0 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-3228
Radar None
Original Reporter panchenks (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 8.1 (8B62)

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

md5: 7667cb8d05691fdda7443fdf7f22f62b

duplicates:

  • SR-2935 It is possible to "hide" methods imported from Obj-C via NS_SWIFT_NAME in extensions

Issue Description:

According to Swift documentation,

Extensions can add new functionality to a type, but they cannot override existing functionality.

However, the compiler silently allows the redeclaration of properties and functions for classes from included frameworks, and does not generate warnings or errors.

For example, suppose we have the following class declared in a framework:

public class DemoClass {
    public var someVariable: String {
        return "String"
    }
}

That framework is included in the project of an app, where the following extension is introduced:

extension DemoClass {
    var someVariable: Int {
        return 1
    }
}

Unlike you'd expect, there is no error or warning here. In fact, if the class was declared in the app and not the framework, we'd get an "Invalid redeclaration" compile error. Instead, the variable is silently overridden, now returning an Int in this example.

This is also the case for functions.

Example project here: https://github.com/panchenks/ExtensionBugApp

@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

1 participant