[swift-evolution] Analysis of existing scopes

Joanna Carter joanna at carterconsulting.org.uk
Thu Feb 23 04:47:13 CST 2017


And now I find, what I consider to be, a very peculiar anomaly in method visibility.

private class PrivateBaseClass
{
  internal func internalFunc() { }
  
  public func publicFunc() { }
  
  open func openFunc() { }
}

private class PrivateDerivedClass : PrivateBaseClass
{
  fileprivate override func internalFunc() { }
  
  fileprivate override func publicFunc() { }
  
  fileprivate override func openFunc() { }
}

internal class InternalDerivedFromPrivateClass : PrivateBaseClass { } // error : Class cannot be declared internal because its superclass is fileprivate



Can somebody please explain why I can declare internal, public and open members on a private class, and even override them in a derived private class, all without even a compiler warning, when, as soon as I try to extend the visibility of a private class, I am told that I cannot so do.

I mean, it is blatantly obvious why you would not want higher visibility members in a limited visibility class, so why doesn't the compiler simply state that all members cannot have a visibility higher than the declaring class?

--
Joanna Carter
Carter Consulting



More information about the swift-evolution mailing list