Small inconsistency with public-private access modifiers

It seems like this doesn't rise an error or warning (at least not in Swift 5.6), although it makes little sense to have a public func inside a private struct/class/actor.

private struct MyStruct {
    public func something() { ... }

I suppose it's an not expected behaviour? Possibly a tiny bug?

This is deliberately permitted.

The stated reason is that you can design a public type, choosing which members are public or not, while keeping the type itself internal or private while work is in progress, then change only one access modifier to make it public.

The pragmatic reason is that there is no way to spell a member with the same visibility as a containing private type, since private-inside-the-type is less than private-for-the-type, so Swift must allow members inside private types to have higher access modifiers.


There is a SwiftLint rule that would catch this: Lower ACL than parent.

1 Like