Skip to content

Emit fix-its for Return from initializer missing variables #80945

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
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

iMostfa
Copy link
Contributor

@iMostfa iMostfa commented Apr 21, 2025

Resolves #80944

11223.mov

This's my proposed solution for the issue.

the proposed solution:

  1. Check the currently passed parameters in the init(....) function
  2. suggest a fix it on the init to add ,foo: Bar
  3. suggest a fix on the closing brace, to add self.foo = foo after { which is the opening of brace of init function

take the as input:

struct Foo {
    let name: String
    let k: (String, Int)
    let m: String

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

the following fix-its are emitted:

[
 {
  "file": "/Users/mostafa.essam/Desktop/file2.swift",
  "offset": 143,
  "text": "self.k = k\nself.m = m\n"
 },
 {
  "file": "/Users/mostafa.essam/Desktop/file2.swift",
  "offset": 110,
  "text": ",k: (String, Int)"
 }
]

when applied, it will result to:

struct Foo {
    let name: String
    let k: (String, Int)
    let m: String

    init(name: String, m: String, k: (String, Int)) {
        self.name = name
        self.k = k
        self.m = m
    }
}

i opened the PR to discuss the solution

@iMostfa
Copy link
Contributor Author

iMostfa commented Apr 23, 2025

Hi @eeckstein would love to have your input here please🙏🏻

@eeckstein
Copy link
Contributor

I'm probably not the best person to review this. Maybe @rintaro can take a look?
But please first bring your changes in a better shape. For example, indentation is completely wrong.
Also, I don't understand your motivating example in the description.

@iMostfa iMostfa changed the title Emit fix-its for Return from initializer Emit fix-its for Return from initializer missing variables Apr 24, 2025
@iMostfa
Copy link
Contributor Author

iMostfa commented Apr 24, 2025

@eeckstein I updated the example; I had accidentally pasted the output into the input earlier 🫠
i also updated the indentation.

additionally, i updated the PR with a video showing the change from Xcode, a little bit easier when visualized, the fix-it is what this PR is trying to add

@iMostfa
Copy link
Contributor Author

iMostfa commented Apr 25, 2025

@rintaro would love to have your input on my PR please 🙏🏻

@rintaro
Copy link
Member

rintaro commented Apr 29, 2025

Apologies for not replying sooner.
I can review the diagnostic code, but I'm not familiar with these DI APIs e.g. DIMemoryUse. From the history maybe @slavapestov ?

But before that, please add some test cases. You could update test/SILOptimizer/definite_init_*.swift

@iMostfa iMostfa force-pushed the feature/generate-init-fixit branch from 34b9b52 to 87253b8 Compare May 3, 2025 18:11
@iMostfa
Copy link
Contributor Author

iMostfa commented May 3, 2025

tests updated with the new expected fix-its.
can you @slavapestov take a look ? 👀

@iMostfa
Copy link
Contributor Author

iMostfa commented May 7, 2025

ping 🙏🏻

@iMostfa
Copy link
Contributor Author

iMostfa commented Jun 7, 2025

@eeckstein Hi, can you suggest any reviewer for the PR ? 🙏🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Emit fix-its for Return from initializer without initializing all stored properties
3 participants