Files
swift-collections/Tests/_CollectionsTestSupport
Joseph CursioandClaude Opus 5 c0c4b3bfad Report a mis-sized expectation instead of trapping or ignoring it
validateContainer checked the container's own count, underestimatedCount
and isEmpty for consistency, but never compared count against the number
of expected contents. Every loop that follows is bounded by the
container's count and indexes expectedContents at the same offset, so the
two failure modes were:

- A short expectation ran off the end. Where the expectation is a prefix
  of the contents it matches its way to the end and then traps with
  "Fatal error: Index out of range", killing the test process instead of
  reporting a validation failure.

- A long expectation was accepted. Offsets past the container's count are
  never looked at, so an expectation of twice the length passed.

The second is the worse of the two: a test can assert far less than it
appears to, and nothing says so.

One guard fixes both, placed after the container's own count consistency
checks so that a container with a broken count still reports that rather
than a size mismatch.

The regression test uses dropLast rather than dropFirst, and the comment
says why: dropFirst shifts every element, so a content mismatch at offset
0 is reported before the out-of-bounds access happens. That masks the
defect by coincidence rather than guarding against it, and a test written
that way would have passed against the unfixed code for the wrong reason.

Watched failing before the fix: the short case trapped with signal 5, the
long case reported "an expectation of 8 items must not validate against a
container of 4". Full suite with --traits UnstableContainersPreview: 893
tests, 0 failures, so none of the six existing checkContainer call sites
was relying on either behaviour.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-23 08:02:40 -05:00
..