Skip to content

Fix #2430: Hide 'Convert to computed property' for Void functions#2433

Merged
ahoppen merged 4 commits intoswiftlang:mainfrom
DPrakashhh:fix/no-computed-property-for-void-2430
Jan 8, 2026
Merged

Fix #2430: Hide 'Convert to computed property' for Void functions#2433
ahoppen merged 4 commits intoswiftlang:mainfrom
DPrakashhh:fix/no-computed-property-for-void-2430

Conversation

@DPrakashhh
Copy link
Copy Markdown
Contributor

@DPrakashhh DPrakashhh commented Jan 6, 2026

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.

Screenshot 2026-01-06 at 1 53 05 PM Screenshot 2026-01-06 at 1 53 36 PM

Open for any changes :)

@DPrakashhh DPrakashhh force-pushed the fix/no-computed-property-for-void-2430 branch 4 times, most recently from fa34a01 to 48d8304 Compare January 6, 2026 08:43
Comment thread Tests/SourceKitLSPTests/CodeActionTests.swift Outdated
@DPrakashhh
Copy link
Copy Markdown
Contributor Author

On it :)

@DPrakashhh
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback, I have updated the PR with a new commit that switches to the TypeSyntax extension logic you suggested. I also cleaned up the guard bindings and refactored the tests to use assertCodeActions to keep things concise. Ready for another look!

Copy link
Copy Markdown
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some leftover code, otherwise looks good to me 👍🏽

@DPrakashhh
Copy link
Copy Markdown
Contributor Author

DPrakashhh commented Jan 8, 2026

Done!

@DPrakashhh DPrakashhh requested a review from ahoppen January 8, 2026 09:52
Copy link
Copy Markdown
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, let’s get it in.

@ahoppen
Copy link
Copy Markdown
Member

ahoppen commented Jan 8, 2026

@swift-ci Please test

@ahoppen
Copy link
Copy Markdown
Member

ahoppen commented Jan 8, 2026

@swift-ci Please test Windows

@ahoppen ahoppen merged commit fc876d0 into swiftlang:main Jan 8, 2026
3 checks passed
@DPrakashhh
Copy link
Copy Markdown
Contributor Author

Thank you! for merging it :D

@DPrakashhh DPrakashhh deleted the fix/no-computed-property-for-void-2430 branch January 8, 2026 18:35
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.

2 participants