-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
access controlFeature → modifiers: Access control and access levelsFeature → modifiers: Access control and access levelscompilerThe Swift compiler itselfThe Swift compiler itselffeatureA feature request or implementationA feature request or implementationmemberwise initFeature: Memberwise structure initializersFeature: Memberwise structure initializersswift evolution proposal neededFlag → feature: A feature that warrants a Swift evolution proposalFlag → feature: A feature that warrants a Swift evolution proposal
Description
Description
Consider the following code:
struct Struct {
var x: Int
private var y: Int = 0
}
do {
let _ = Struct(x: 0)
}
Despite x
not being private, the "inaccessible initializer" error is emitted.
One fix is to change y
to a constant so that it doesn’t contribute to the generated initializer:
struct Struct {
var x: Int
private let y: Int = 0
}
However, this is not always a desired behavior.
Solution
Generate an additional, internal
memberwise initializer for x
, or more fine control over which properties contribute to the generated init.
ApolloZhu
Metadata
Metadata
Assignees
Labels
access controlFeature → modifiers: Access control and access levelsFeature → modifiers: Access control and access levelscompilerThe Swift compiler itselfThe Swift compiler itselffeatureA feature request or implementationA feature request or implementationmemberwise initFeature: Memberwise structure initializersFeature: Memberwise structure initializersswift evolution proposal neededFlag → feature: A feature that warrants a Swift evolution proposalFlag → feature: A feature that warrants a Swift evolution proposal