Skip to content

Analysis: CopyArray mutation usage in endojs/endo#3063

Draft
Copilot wants to merge 4 commits intomfig/readonly-array-is-passablefrom
copilot/sub-pr-3061
Draft

Analysis: CopyArray mutation usage in endojs/endo#3063
Copilot wants to merge 4 commits intomfig/readonly-array-is-passablefrom
copilot/sub-pr-3061

Conversation

Copy link
Contributor

Copilot AI commented Jan 29, 2026

Identified all arrays declared as CopyArray that are subsequently mutated in the repository, confirming that CopyArray must remain mutable to avoid breaking changes.

Findings

Production code mutations (packages/patterns/src/patterns/patternMatchers.js):

  • confirmElementsHasSplit(): Optional inResults and outResults parameters typed as CopyArray are mutated via .push()
  • pairsHasSplit(): Optional inResults and outResults parameters typed as CopyArray<[Key, bigint]> are mutated via .push()

Test code mutations (packages/pass-style/src/types.test-d.ts):

  • Explicit tests verify CopyArray supports mutation methods (.push(), .shift())

Example Usage

const confirmElementsHasSplit = (
  elements,
  elementPatt,
  bound,
  reject,
  inResults = undefined,     // CopyArray - mutated
  outResults = undefined,    // CopyArray - mutated
) => {
  for (let i = elements.length - 1; i >= 0; i -= 1) {
    const element = elements[i];
    if (count < bound && matches(element, elementPatt)) {
      if (inResults) inResults.push(element);  // mutation
    } else if (outResults) {
      outResults.push(element);  // mutation
    }
  }
};

Analysis confirms that changing CopyArray from Array<T> to ReadonlyArray<T> would break existing code. The separate CopyReadonlyArray type introduced in #3061 maintains backward compatibility.

Complete analysis available in /tmp/copyarray-analysis/FINAL-REPORT.md.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Update CopyArray compatibility with ReadonlyArray Analysis: CopyArray mutation usage in endojs/endo Jan 29, 2026
Copilot AI requested a review from michaelfig January 29, 2026 04:41
@michaelfig michaelfig force-pushed the mfig/readonly-array-is-passable branch 3 times, most recently from e5684ea to 8d8a604 Compare January 30, 2026 10:22
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.

2 participants