Skip to content

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

@iMostfa

Description

@iMostfa

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureA feature request or implementationtriage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions