Internal/private structs/classes with public members are not diagnosed:
// foo.swift
private struct Struct {
public var x: Int
}
private class Class {
public var x: Int = 0
}
They're also synthesized with an internal memberwise initializer:
$ swiftc -print-ast foo.swift
private struct Struct {
public var x: Int
internal init(x: Int)
}
private class Class {
@_hasInitialValue public var x: Int
@objc deinit
internal init()
}
Is this intentional? Is there value in supporting nominal type declarations with members of a higher access level?
Yes, this is intentional and was heavily discussed during the access-control proposals.
The purpose is to allow a developer to prepare for making a type more visible, by marking all the members with the visibility that they would eventually like them to have, and then when they are ready to make the type visible, that can be done with a single change to the type’s access level.