Skip to content

Emit fix-its for Return from initializer without initializing all stored properties #80944

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

Open
iMostfa opened this issue Apr 21, 2025 · 1 comment · May be fixed by #80945
Open

Emit fix-its for Return from initializer without initializing all stored properties #80944

iMostfa opened this issue Apr 21, 2025 · 1 comment · May be fixed by #80945
Labels
feature A feature request or implementation triage needed This issue needs more specific labels

Comments

@iMostfa
Copy link
Contributor

iMostfa commented Apr 21, 2025

Motivation

when adding new declarations to any data type (class, struct, actor)
it will be nice if the compiler suggest fix-its to init the newly added declarations

Image

Proposed solution

it will be nice if the compiler provides two fix-its

  1. appearing on the init that if applied, will add the new missing parameters
  2. appearing on the closing brace of init, to add self.foo=foo
struct Foo {
    let name: String
    let age: Int  //<- newly added variable

    init(name: String) {
        self.name = name
    }
}

the two fix-its should be:

[
 {
  "file": "/Users/mostafa.essam/Desktop/file2.swift",
  "offset": 106,
  "text": "\nself.age = age\n"
 },
 {
  "file": "/Users/mostafa.essam/Desktop/file2.swift",
  "offset": 73,
  "text": ",age: Int"
 }
]

Alternatives considered

No response

Additional information

No response

@iMostfa iMostfa added feature A feature request or implementation triage needed This issue needs more specific labels labels Apr 21, 2025
@iMostfa
Copy link
Contributor Author

iMostfa commented Apr 21, 2025

PR opened

#80945

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request or implementation triage needed This issue needs more specific labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant