Uploaded image for project: 'Swift'
  1. Swift
  2. SR-5982

didSet causes unwanted calls to getter even when oldValue isn't used

    XMLWordPrintable

    Details

      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.

        Attachments

          Activity

            People

            Assignee:
            suyashsrijan Suyash Srijan
            Reporter:
            rjmccall John McCall
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: