Skip to content

[SR-7082] Reconsider prohibition on overriding a property with a stored property #49630

@jckarter

Description

@jckarter
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselffeatureA feature request or implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions