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

"Simultaneous access" error is too strict for access to self in mutating methods

    XMLWordPrintable

    Details

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

      Apple Swift version 4.0 (swiftlang-900.0.43 clang-900.0.22.8)
      Target: x86_64-apple-macosx10.9

      Description

      In Swift 3.2 and Swift 4, the new exclusive memory access model is a bit too strict when looking at mutating methods of structs. Mutating methods that mutate two different stored properties of self in the same expression are considered to be in error, even though this is a perfectly normal thing to want to do and should be safe.

      For example:

      struct Foo {
          mutating func bar() {
              _ = utf8.decode(&iter)
          }
      
          var utf8 = UTF8()
          var iter: String.UTF8View.Iterator
      }
      

      This complains about the utf8.decode(&iter), as this modifies both the utf8 and iter properties. These are stored properties without property observers, so the accesses to the properties are wholly independent.

      This affects the PMJSON library.

        Attachments

          Activity

            People

            Assignee:
            lily Lily Ballard
            Reporter:
            lily Lily Ballard
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: