Skip to content

Detect-Target returns "win32-arm64 arm64" instead of `"win32-arm64" on ARM64 Windows #2135

Description

@JanDeDobbeleer

What version of Kimi Code is running?

None

Which open platform/subscription were you using?

None

Which model were you using?

None

What platform is your computer?

Windows ARM64

What issue are you seeing?

The Detect-Target function in [file/path] returns a malformed target string of win32-arm64 arm64 on ARM64 Windows machines, instead of the expected win32-arm64.

Root Cause

The switch statement matches architecture strings case-insensitively by default, and PowerShell's switch does not stop after the first match unless a break is explicitly added to each case:

$arch = switch ($rawArch) {
    'X64'     { 'x64' }
    'X86'     { 'x86' }
    'Arm64'   { 'arm64' }
    'ARM64'   { 'arm64' }
    'AMD64'   { 'x64' }
    'IA64'    { 'ia64' }
    default   { Die "unsupported architecture: $rawArch" }
}

On an ARM64 machine, $rawArch is the literal string "ARM64", which matches both the 'Arm64' and 'ARM64' cases (case-insensitive, no break). Both blocks execute, producing the array @('arm64', 'arm64') instead of a single string. When that array is interpolated in "win32-$arch", PowerShell joins the elements with a space (via $OFS), producing win32-arm64 arm64.

Fix

Remove the redundant duplicate case and add break to every case to prevent this class of bug in general:

$arch = switch ($rawArch) {
    'X64'     { 'x64'; break }
    'X86'     { 'x86'; break }
    'ARM64'   { 'arm64'; break }
    'AMD64'   { 'x64'; break }
    'IA64'    { 'ia64'; break }
    default   { Die "unsupported architecture: $rawArch" }
}

Environment

  • OS: Windows on ARM64
  • PowerShell version: [fill in, e.g. 7.4.x or 5.1]

Steps to Reproduce

  1. Run Detect-Target on a Windows ARM64 machine.
  2. Observe the returned value is win32-arm64 arm64 instead of win32-arm64.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions