swift icon indicating copy to clipboard operation
swift copied to clipboard

Init Accessors with nonmutating modify fails to compile

Open mansbernhardt opened this issue 7 months ago • 5 comments

Description

This is a follow up to the following issue: https://github.com/swiftlang/swift/issues/67827

Reproduction


struct Test {
  let id: UUID
  private var _count: Int

  var count: Int
  {
    @storageRestrictions(initializes: _count)
    init {
      _count = newValue
    }
    _read {
      yield _count
    }
    nonmutating _modify {
      var val = _count
      yield &val
    }
  }

  init(id: UUID, count: Int) {
    self.id = id
    self.count = count // << Variable 'self._count' used before being initialized
  } // << Return from initializer without initializing all stored properties
}

Expected behavior

The above code should compile without errors.

Environment

The initial Xcode beta

Additional information

No response

mansbernhardt avatar Jul 08 '24 19:07 mansbernhardt