Struct initializer is inaccessible due to private protection level from its own file

It turns out that the initializer's protection level is only as open as the most open instance variable.

If I make the string instance variable anything other than private, the error goes away:

private struct A {
  let string: String
  // default initializer: init(string: String)
  func foo() {}
}

So given that B can now read A's string, it can also access A's initializer.

If A had another private property though, then again its initializer would become private:

private struct A {
  let string: String
  private let int: Int
  // default initializer: private init(string: String, int: Int)
  func foo() {}
}

Tags:

Swift