Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: ChangeAwareList incorrectly consolidates clears #885

Closed
JakenVeina opened this issue Mar 25, 2024 · 1 comment · Fixed by #892
Closed

[Bug]: ChangeAwareList incorrectly consolidates clears #885

JakenVeina opened this issue Mar 25, 2024 · 1 comment · Fixed by #892
Assignees
Labels

Comments

@JakenVeina
Copy link
Collaborator

JakenVeina commented Mar 25, 2024

Describe the bug 🐞

ChangeAwareList<T>.CaptureChanges() contains logic to consolidate separate remove changes together to form a Clear operation, if it detects that the collection is empty upon capture. This logic produces invalid changesets, under some circumstances.

  1. Non-removal changes, such as Refresh that occurred since the last capture get ignored, which could arguably be a desirable behavior, since refreshing an item is pointless if it's soon-to-be removed. Personally, I think one could also argue this is an assumption we shouldn't make.
  2. Items can appear in duplicate, within the produced Clear changeset, which I think is much more problematic. Downstream consumers that seek to actually inspect removed items, for post-processing, seem likely to rely on the the idea of only post-processing each item once.

Step to reproduce

var uut = new ChangeAwareList<int>();

uut.AddRange(new[] { 1, 2, 3, 4, 5 });
uut.CaptureChanges();

uut.RefreshAt(2);
uut.RemoveAt(1);
uut.Clear();

var result = uut.CaptureChanges();

Here we can see that result does not include a Refresh for item 3, and the Clear lists item 3 twice.

@JakenVeina JakenVeina added the bug label Mar 25, 2024
@JakenVeina JakenVeina linked a pull request Apr 3, 2024 that will close this issue
@JakenVeina JakenVeina self-assigned this Apr 4, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant