Maintenance: PlaybackRegisterAction - Replace arrayOf workaround with idiomatic Kotlin#1743
Open
claude[bot] wants to merge 1 commit intomasterfrom
Open
Maintenance: PlaybackRegisterAction - Replace arrayOf workaround with idiomatic Kotlin#1743claude[bot] wants to merge 1 commit intomasterfrom
claude[bot] wants to merge 1 commit intomasterfrom
Conversation
…omatic Kotlin The `arrayOf(false)` pattern was a Java-style workaround for capturing a mutable variable, unnecessary here since there are no lambdas involved. Replace with a `var`, use `when` as an expression with a direct `return`, and swap the manual while-loop counter for a `for` range. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/action/macro/PlaybackRegisterAction.ktarrayOf(false)pattern used as a Java-style mutable-variable workaroundexecute()to use idiomatic KotlinDetails
The original code used
val res = arrayOf(false)and mutatedres[0]throughout awhenblock before returningres[0]. This pattern comes from Java where you need an effectively-final container to capture a mutable value inside a closure — but this code has no closures, so the array was completely unnecessary.Changes:
arrayOf(false)+res[0]assignments with avar successlocal andwhenused as an expression with a directreturnwhile (i < cmd.count) { ... i += 1 }loop with afor (i in 0 until cmd.count)range (semantically identical, more idiomatic)whenbranches from block form-> { res[0] = expr }to inline-> exprWhy this improves the code
The
arrayOfworkaround obscures intent and surprises Kotlin readers — it implies there's some shared-state or closure reason for the array that doesn't exist. The refactored version reads as straightforward control flow and is 8 lines shorter.🤖 Generated with Claude Code