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

lazy variable resetting no longer works, but breaking change wasn't documented

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:
    • Environment:

      Description

      As of Swift 3.2, the behavior described here was possible and reliable. In Swift 4, it results in the value being `nil` forever.

      While I agree this change makes the language more consistent and predictable, it wasn't documented anywhere I can find.


      Test:

      class Lazy {
          lazy var test: String! = "original value"
      }
      
      let l = Lazy()
      
      l.test // "original value"
      l.test = "new"
      l.test // "new"
      l.test = nil
      assert(l.test != nil, "In Swift 3, lazy value is re-initialized")
      

        Attachments

          Activity

            People

            Assignee:
            slavapestov Slava Pestov
            Reporter:
            BenLeggiero Ben Leggiero
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: