Skip to content

Maintenance: PlaybackRegisterAction - Replace arrayOf workaround with idiomatic Kotlin#1743

Open
claude[bot] wants to merge 1 commit intomasterfrom
maintenance/playback-register-action-refactor
Open

Maintenance: PlaybackRegisterAction - Replace arrayOf workaround with idiomatic Kotlin#1743
claude[bot] wants to merge 1 commit intomasterfrom
maintenance/playback-register-action-refactor

Conversation

@claude
Copy link
Copy Markdown

@claude claude Bot commented May 5, 2026

Summary

  • Area inspected: vim-engine/src/main/kotlin/com/maddyhome/idea/vim/action/macro/PlaybackRegisterAction.kt
  • Issue found: Non-idiomatic arrayOf(false) pattern used as a Java-style mutable-variable workaround
  • Changes made: Refactored execute() to use idiomatic Kotlin

Details

The original code used val res = arrayOf(false) and mutated res[0] throughout a when block before returning res[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:

  • Replaced arrayOf(false) + res[0] assignments with a var success local and when used as an expression with a direct return
  • Replaced the manual while (i < cmd.count) { ... i += 1 } loop with a for (i in 0 until cmd.count) range (semantically identical, more idiomatic)
  • Collapsed single-expression when branches from block form -> { res[0] = expr } to inline -> expr

Why this improves the code

The arrayOf workaround 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

…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>
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.

0 participants