Skip to content

Keep view counts consistent when a range insertion throws - #147

Closed
Mountaindonkey wants to merge 1 commit into
Cysharp:masterfrom
Mountaindonkey:fix/view-count-after-range-projection-error
Closed

Mountaindonkey wants to merge 1 commit into
Cysharp:masterfrom
Mountaindonkey:fix/view-count-after-range-projection-error

Conversation

@Mountaindonkey

Copy link
Copy Markdown

Fixes #144.

ObservableList<T> increments the synchronized view's count while projecting a range. When a later selector or filter call throws, earlier matches have been counted even though none of the new items have been inserted into the view.

Count matches locally, then update the view's count after the range is inserted and before notifying subscribers. Exceptions still propagate to the caller. The source list has already accepted the range when it notifies the view.

Added regression tests for AddRange with a throwing selector and InsertRange with a throwing filter. Both reproduced an off-by-one count on master.

Tests

  • Core suite passed on .NET 8 and .NET 10 (112 tests each).
  • The same 112 tests passed against the .NET Standard 2.1 build used by Unity.
  • R3 integration tests passed on .NET 8 and .NET 10 (12 tests each).

Prepared and tested with OpenAI Codex.

Count matching entries locally while projecting a range, then apply the count after insertion and before notifying view subscribers. Exercise both a throwing selector on AddRange and a throwing filter on InsertRange.
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.

A throwing selector during a range insertion leaves a wrong Count on the view

1 participant