Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-5714] Memberwise initializer should adopt struct access control #48284

Open
swift-ci opened this issue Aug 18, 2017 · 3 comments
Open

[SR-5714] Memberwise initializer should adopt struct access control #48284

swift-ci opened this issue Aug 18, 2017 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself feature A feature request or implementation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5714
Radar rdar://problem/18065955
Original Reporter erica (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 5
Component/s Compiler
Labels Bug, LanguageFeatureRequest
Assignee None
Priority Medium

md5: ddb1f014e36d7ba2b77e693c26f30092

relates to:

  • SR-5534 Memberwise initializers with any number of optional properties

Issue Description:

If the struct is public, the memberwise init should be automatically created and set public

@huonw
Copy link
Mannequin

huonw mannequin commented Aug 23, 2017

I think there's an argument to be made for making the memberwise init public if all of the members are public, but not if only the struct is. Doing the latter would make it very easy to accidentally expose an unintentional init to downstream users, and one that changes when members are changed (i.e. one could only modify private code, and still stop downstream code from compiling).

Something that might handle both cases is being able to opt in to the compiler filling in the initializer body if the signature is right, e.g. C++-style public init(x: Int, y: Int) = default or something. This means that any (incompatible) changes to the struct's members will stop the defaulted initializer from compiling, alerting the programmer that they may be breaking downstream code.

@belkadan
Copy link
Contributor

Right. This isn't just a bug; it was a deliberate design decision, based on the principle that exposing API across a library boundary should always be explicit.

@belkadan
Copy link
Contributor

It's on swift-evolution to come up with a solution and proposal for this.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself feature A feature request or implementation
Projects
None yet
Development

No branches or pull requests

2 participants