Skip to content

Fix lost writes after ?? and || defaults - #616

Open
KayleeWilliams wants to merge 1 commit into
vercel-labs:mainfrom
KayleeWilliams:fix/nullish-default-writes
Open

KayleeWilliams wants to merge 1 commit into
vercel-labs:mainfrom
KayleeWilliams:fix/nullish-default-writes

Conversation

@KayleeWilliams

Copy link
Copy Markdown

I hit this moving our CLI (inthhq/inth) to 0.2. parseArguments passes result to a function that sets skillsArguments, and on 0.2 the caller never sees the write. Smaller repro:

interface Args { command: string; extra?: string[] }
const fill = (options: Args, values: string[]): void => { options.extra = values; };
const parse = (args: string[]): Args => {
  const result: Args = { command: "" };
  for (let i = 0; i < args.length; i += 1) {
    if (args[i] === "skills") { fill(result, args.slice(i + 1)); return result; }
  }
  result.command = args[0] ?? "";
  return result;
};
console.log(parse(["skills", "--yes"]).extra);
// Node: [ '--yes' ]
// 0.2.1: undefined

mayBeOptional treats a ?? b and a || b as optional if either side is, but both give b when a is undefined. So args[0] ?? "" counted as optional, result got a widened shape, and the call to fill went through a %rec.width copy. This checks only the right side for ?? and ||.

nullish-default-record-writes.ts fails on main and passes with this. The rest of the corpus passes too, except 1640-fd-read-decode.ts and 2283-structured-clone.cjs, which fail on main for me as well (Node 24.19). I didn't run the sanitized lane.

The copy itself is still there. With result.command = args[0] and no default, the write is still lost. I wasn't sure how you'd want that fixed, so I left it alone.

@vercel

vercel Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

@KayleeWilliams is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

1 participant