[SR-5982] didSet causes unwanted calls to getter even when oldValue isn't used #48541
Labels
compiler
The Swift compiler in itself
good first issue
Good for newcomers
improvement
observers
Feature → accessors: Stored variable (property) observers (`willSet`, `didSet`)
swift evolution implemented
Flag → feature: A feature that was approved through the Swift evolution process and implemented
Additional Detail from JIRA
md5: 192aa54d355eabb9ee52c40a54ee2184
Issue Description:
didSet takes an implicit oldValue parameter. Actually providing this value when overriding a computed property requires us to call the getter for the superclass. This is wasteful in the common case where this parameter is unused. It can also cause spurious semantic problems, such as an infinite recursion, in complex and somewhat silly cases that do unfortunately arise in Cocoa.
The obvious fix is that, when this parameter is implicit and unused, it should effectively disappear, allowing us to eliminate the call to the getter. This would be a semantic change, and it would require Swift Evolution approval, but I think it would be likely to be accepted.
The text was updated successfully, but these errors were encountered: