Function in private extension must be declared private because it uses a private type?

As someone who was against SE-0025 and SE-0169 I agree with @Nevin's conclusions:

  • Pre-SE-0025, private meant fileprivate, and so private extension meant fileprivate extension.

  • With SE-0025 (but not SE-0169), @xwu's explanation is correct: private extension is effectively still fileprivate because (a) applying private to all members would have been useless, and (b) it was a goal (though not one I agreed with) to make fileprivate rare if people wanted it to be. Therefore, "private means enclosing scope and that includes extensions, which are always at the top level of a file".

  • With SE-0169, private for all methods in an extension became meaningful again…but it would be a source-breaking change to have those methods not exposed to other types in the file. Perhaps that change should have been made in Swift 5 as a breaking change, and I'd be in favor of making that change the next time we break source compatibility, with a corresponding deprecation of private extension in favor of fileprivate extension in existing language modes when we do.

6 Likes