You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
That framework is included in the project of an app, where the following extension is introduced:
extensionDemoClass {
varsomeVariable: Int {
return1
}
}
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.
Environment
Xcode 8.1 (8B62)
Additional Detail from JIRA
md5: 7667cb8d05691fdda7443fdf7f22f62b
duplicates:
Issue Description:
According to Swift documentation,
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:
That framework is included in the project of an app, where the following extension is introduced:
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
The text was updated successfully, but these errors were encountered: