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-5534] Memberwise initializers with any number of optional properties #48106

Closed
swift-ci opened this issue Jul 23, 2017 · 3 comments
Closed
Labels
compiler The Swift compiler in itself duplicate Resolution: Duplicates another issue feature A feature request or implementation improvement memberwise init Feature: Memberwise structure initializers swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5534
Radar rdar://problem/16021750
Original Reporter Bear (JIRA User)
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 3
Component/s Compiler
Labels Improvement, LanguageFeatureRequest
Assignee None
Priority Medium

md5: f7949e46c502a72e96387d53c13e0a96

is duplicated by:

  • SR-5921 Default constructor for structs with default values don't have argument with default value

relates to:

  • SR-5714 Memberwise initializer should adopt struct access control

Issue Description:

Currently, if we don't have our own initializer for the structure, its default memberwise initializer allows to provide values of all properties. If we assign a default value for all of our properties, additional initializer in shape of init() becomes available to use.

It would be a lot more convenient to make structure initializer behave more like a function with default values.

Example:

struct S {
    var a: Int
    var b = 1
    var c: Int
}

var s1 = S(a: 0, c: 2)
var s2 = S(a: 10, b: 11, c: 12)

Are there any potential problems with such behavior?

@belkadan
Copy link
Contributor

For memberwise initializers within a module it's totally sensible (and we've had a Radar to do it for a long time). If the proposal to expose them outside a module goes through, however, it gets trickier: initial values are normally not part of a struct's exposed API, but default arguments are.

@DougGregor
Copy link
Member

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented memberwise init Feature: Memberwise structure initializers duplicate Resolution: Duplicates another issue labels Nov 12, 2022
@AnthonyLatsis
Copy link
Collaborator

Duplicate of #43955

@AnthonyLatsis AnthonyLatsis marked this as a duplicate of #43955 Nov 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself duplicate Resolution: Duplicates another issue feature A feature request or implementation improvement memberwise init Feature: Memberwise structure initializers swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented
Projects
None yet
Development

No branches or pull requests

4 participants