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

Fix failing duplicate identifier detection #375

Closed
wants to merge 2 commits into from

Conversation

teameh
Copy link

@teameh teameh commented Oct 8, 2020

Diff.differencesForSectionedView(initialSections:finalSections:)

Is not throwing Duplicate item or Duplicate section error's when finalSections contains duplicates while initialSections did not.

I'll see if I can add the fix to this pull request as well.

@teameh
Copy link
Author

teameh commented Oct 8, 2020

I've also added a fix for the bug. I don't need to create a separate issue for this right?

@teameh teameh changed the title Add tests that show failing duplicate identifier detection Fix failing duplicate identifier detection Oct 8, 2020
throw Error.duplicateItem(item: item)
}
finalKeys.insert(key)

guard let initialItemPathIndex = dictionary[key] else {
continue
Copy link
Author

@teameh teameh Oct 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that if the item was not present in the initial sections, we always continue and it's never checked if the finalSections contain items with duplicate identifiers!

throw Error.duplicateSection(section: section)
}
finalSectionIdentities.insert(section.identity)

guard let initialSectionIndex = initialSectionIndexes[section.identity] else {
continue
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, we need to not only look in the initialSectionIndexes but also store the identity in an extra Set (any better data types for this use case?) and check if the final sections don't contain any duplicates

]

do {
_ = try Diff.differencesForSectionedView(initialSections: [], finalSections: final)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix this will not throw

@@ -332,7 +401,7 @@ extension AlgorithmTests {
]

do {
_ = try Diff.differencesForSectionedView(initialSections: initial, finalSections: initial)
_ = try Diff.differencesForSectionedView(initialSections: [], finalSections: final)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix this will not throw

@@ -357,7 +451,7 @@ extension AlgorithmTests {
]

do {
_ = try Diff.differencesForSectionedView(initialSections: initial, finalSections: initial)
_ = try Diff.differencesForSectionedView(initialSections: [], finalSections: final)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix this will not throw

@freak4pc freak4pc closed this Jan 2, 2021
@freak4pc freak4pc deleted the branch RxSwiftCommunity:master January 2, 2021 09:40
@teameh
Copy link
Author

teameh commented Jan 4, 2021

@freak4pc I see you closed this? Is the issue fixed in 6.0.0?

@freak4pc
Copy link
Member

freak4pc commented Jan 4, 2021

Can you reopen this against main? I changed the main branch name and apparently it closed all the PRs leading to it 🤦‍♂️🤦‍♂️🤦‍♂️

@teameh
Copy link
Author

teameh commented Jan 4, 2021

Haha maybe that's what happened at apple as well? 😜 here you go #390

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