Skip to content

Add inline function refactoring#3318

Open
Padmashree06 wants to merge 1 commit into
swiftlang:mainfrom
Padmashree06:function-Inlining-keep-original
Open

Add inline function refactoring#3318
Padmashree06 wants to merge 1 commit into
swiftlang:mainfrom
Padmashree06:function-Inlining-keep-original

Conversation

@Padmashree06

Copy link
Copy Markdown
Contributor

Explanation:

Add refactoring to inline function at function call.

  1. If the function body consists of a single return statement, the returned expression is inlined directly.
  2. For multi-statement or void functions, the body is wrapped in a closure and invoked.
  3. Function parameters are replaced by arguments provided at function call.

Test cases are written for the same.

Scope:

This will provide refactoring to inline functions at function call and will be wired as a codeAction in sourcekit-lsp.

Issues:

swiftlang/sourcekit-lsp#2508

Original PRs:

Not Applicable

Risk:

This is a standalone feature and does not change the existing structure or functionality of the code.
It is a additional feature.

Testing:

Added unit tests covering:

  • Simple return expression inlining
  • Multiple parameters
  • Multi-statement functions (closure wrapping)
  • Void functions
  • Failure cases (missing function, argument mismatch, method calls)

All tests pass locally using swift test.

Reviewers:

Not Applicable

@Padmashree06 Padmashree06 requested a review from a team as a code owner April 15, 2026 21:35

@ahoppen ahoppen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have not looked at the PR in detail, but based on the size of it, I don’t think that it correctly handles argument to parameter matching. See swiftlang/sourcekit-lsp#2506 (comment) for some pointers of what the tricky areas here are. A prerequisite for this refactoring action would be to have a library that allows mapping arguments in arbitrary function calls to the parameters on their declaration.

@Padmashree06

Copy link
Copy Markdown
Contributor Author

Thank you I'll look into it.

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