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

Swift should diagnose infinite recursion of property observers

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:
      None

      Description

      In https://github.com/apple/swift/pull/15526 we changed the behaviour of setting a property within its own didSet or willSet observer, such that we only perform direct accesses on self in Swift 5 mode.

      However this means that code like this will now infinitely recurse:

      struct S {
        var i = 0 {
          didSet {
            var s = self
            s.i = 5
          }
        }
      }
      
      var s = S()
      s.i = 2
      

      Ideally we should diagnose this with a warning.

        Attachments

          Activity

            People

            Assignee:
            CodaFi Robert Widmann
            Reporter:
            originaluser2 Hamish Knight
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: