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-5921] Default constructor for structs with default values don't have argument with default value #48480

Closed
NachoSoto opened this issue Sep 18, 2017 · 1 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

Comments

@NachoSoto
Copy link
Contributor

Previous ID SR-5921
Radar None
Original Reporter @NachoSoto
Type Improvement
Status Resolved
Resolution Duplicate
Environment

Swift version 4.0 (swiftlang-900.0.63 clang-900.0.37)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement
Assignee None
Priority Medium

md5: 105944886c15424a8e6da2a6070408e9

duplicates:

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

Issue Description:

Consider this struct:

struct A {
    let a1: String
    let a2: Int = 0
}

This works:

_ = A(a1: "") // a2 is 0

However, this doesn't:

error.swift:7:15: error: extra argument 'a2' in call
_ = A(a1: "", a2: 1)
              ^

This is unintuitive. One would expect the default constructor for this struct to be defined as:

init(a1: String, a2: Int = 0) {
    self.a1 = a1
    self.a2 = a2
}

And not what currently seems to be defined as:

init(a1: String) {
    self.a1 = a1
    self.a2 = 0
}
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added feature A feature request or implementation duplicate Resolution: Duplicates another issue swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented memberwise init Feature: Memberwise structure initializers labels Nov 12, 2022
@AnthonyLatsis
Copy link
Collaborator

duplicate of #43955

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

2 participants