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-7082] Reconsider prohibition on overriding a property with a stored property #49630

Open
jckarter opened this issue Feb 26, 2018 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself feature A feature request or implementation

Comments

@jckarter
Copy link
Member

Previous ID SR-7082
Radar None
Original Reporter @jckarter
Type Bug
Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug, LanguageFeatureRequest
Assignee None
Priority Medium

md5: 400c319da94f2aeb9aecf260173023c7

Issue Description:

We won't let you override a property from a base class with a stored property:

class Base {
  var property: Int { fatalError("abstract") }
}

class Derived: Base {
  override var property: Int // an error
}

This prohibition came from fear that people might override a property with new storage by accidentally redeclaring the property in their derived class. This decision was made in ancient times before the override keyword was even added and was never revisited. We should reconsider it now that overrides are always explicit.

One remaining potential ambiguity is in the behavior of overrides with observers. Currently, an override with observers always adds the observers on top of the super implementation. If we allow stored properties to be overrides, it may be ambiguous whether an override with didSet/willSet is intended to be a new stored property with and observers or an extension of the base class property with observers.

@belkadan
Copy link
Contributor

Any change here would have to go through the Swift Evolution Process, of course.

@mattneub
Copy link

Along the same lines (I think), it remains surprising (I think) that an initialized `let` property cannot be overridden by another initialized `let` property. It's hard to see what harm that could do.

@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 feature A feature request or implementation
Projects
None yet
Development

No branches or pull requests

3 participants