Fix #2430: Hide 'Convert to computed property' for Void functions#2433
Merged
ahoppen merged 4 commits intoswiftlang:mainfrom Jan 8, 2026
Merged
Conversation
fa34a01 to
48d8304
Compare
48d8304 to
f095486
Compare
ahoppen
reviewed
Jan 6, 2026
Contributor
Author
|
On it :) |
Contributor
Author
|
Thanks for the feedback, I have updated the PR with a new commit that switches to the |
ahoppen
reviewed
Jan 7, 2026
Member
ahoppen
left a comment
There was a problem hiding this comment.
Just some leftover code, otherwise looks good to me 👍🏽
Contributor
Author
|
Done! |
Member
|
@swift-ci Please test |
Member
|
@swift-ci Please test Windows |
Contributor
Author
|
Thank you! for merging it :D |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR resolves issue #2430 by preventing the "Convert to computed property" code action from being suggested for functions that do not return a meaningful value. Converting a function with no return value to a computed property is semantically incorrect and results in nonsensical refactoring.
Changes
1-Logic Enhancement: Updated SyntaxRefactoringCodeActionProvider.swift to include a guard statement that checks for void return types before offering the refactoring.
2-Void Detection Helper: Added a private "isVoidReturnType" helper that robustly identifies:
2.1-Implicit Void: Functions with no return clause.
2.2-Explicit Void: Functions returning Void.
2.3-Empty Tuples: Functions returning ().
3-Normalization: Used whitespace filtering to ensure the check is resistant to formatting variations like -> Void or -> ( ).
4-Regression Tests: Added three comprehensive test cases to CodeActionTests.swift to ensure these scenarios are permanently covered.
Verification Results
1-Automated Tests: Ran swift test --filter CodeActionTests. All 37 tests passed, including the new negative test cases.
2-Manual Verification: Confirmed in VS Code that the refactoring lightbulb is correctly hidden for func test() {} but remains available for functions with actual return types like func test() -> String.
Open for any changes :)