Skip to content

spread operator [...map] produces incorrect results when values are undefined #540

Description

@codehz

What happened

as title

What you expected

Got invalid value

Minimal reproduction

// Minimal reproduction for Perry Map spread operator bug
// The spread operator [...map] produces incorrect results when values are undefined

const map = new Map();
map.set(-4398046512128, undefined);

const spread = [...map];
const arrayFrom = Array.from(map);

console.log("spread length:", spread.length);
console.log("arrayFrom length:", arrayFrom.length);

// In standard JS, both should be equal
console.log("spread[0]:", spread[0]);
console.log("arrayFrom[0]:", arrayFrom[0]);

// This is the actual bug: spread[0] is not an array [key, value]
if (Array.isArray(spread[0])) {
  console.log("spread[0][0]:", spread[0][0]);
  console.log("spread[0][1]:", spread[0][1]);
  console.log("PASS: spread works correctly");
} else {
  console.log("FAIL: spread[0] is not an array, got:", typeof spread[0], spread[0]);
}

// Verify Array.from works correctly
if (Array.isArray(arrayFrom[0]) && arrayFrom[0][0] === -4398046512128 && arrayFrom[0][1] === undefined) {
  console.log("PASS: Array.from works correctly");
} else {
  console.log("FAIL: Array.from also broken");
}

Command you ran:

# e.g. perry compile main.ts -o app --target ios-simulator

Environment

  • Perry version: 0.5.619
  • Host OS: ArchLinux
  • Target: native
  • Rust toolchain (if building from source):
  • Installed via:

Diagnostic output

Perry Doctor

Environment Checks
──────────────────
  ✓ perry version: 0.5.619
  ✓ update status: up to date
  ✓ clang (LLVM codegen): clang version 22.1.3
  ✓ system linker (cc): cc (GCC) 16.1.1 20260430
  ✓ runtime library: target/release/libperry_runtime.a
  ⚠ project config (perry.toml): not found - run: perry init

All critical checks passed with some warnings.

Anything else

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed defect or regression

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions