Can't refer to inner private types declared from an extension

Hi all,

I was decomposing my object by separating different behaviors encapsulated in functions away from the main type declaration in separate types.

Oddly though, I encountered an error. While I can refer to these types when they are declared as private types in a public extension to the container type, in the same file where the main type is declared, same is not possible moving away those extension in separate files each.

It doesn't make sense to me as the access levels for these inner types, as well as extensions', are the same, only thing that differs is the location where they are declared.

It seems an error to me, correct me if I'm wrong, but it should be possible in neither or both ways.
As the inner types declared as private, not fileprivate, are not hidden to the container type in the same file, they should as well be visible from another file.

Thanks for reading.

Check out https://github.com/apple/swift-evolution/blob/master/proposals/0169-improve-interaction-between-private-declarations-and-extensions.md

specifically

Another alternative considered is to allow private members of a type to be accessible to extensions outside of the current source file: either within the current module, or anywhere in the program. This is rejected because it violates an important principle of our access control system: that private is narrower than fileprivate . Allowing private to be narrower in some ways, but broader in other ways (allow access across files) would lead to a more confusing and fractured model.

Thank you for the "Swift" reply :slight_smile:
That makes me wishing more than before an access level scoped for the type (and eventually, subclasses).

1 Like