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

updateValue in InsertionOrderedDictionary fails invariant assertion #141

Open
vadimtrifonov opened this issue Jan 29, 2021 · 0 comments
Open

Comments

@vadimtrifonov
Copy link

When updating the existing key with updateValue method the original index is not set back after acquiring it with indexForKey.updateValue(endIndex, forKey: key).

I believe this should be done after the guard statement:

guard let index = indexForKey.updateValue(endIndex, forKey: key) else {
    elements.append(.init(key: key, value: newValue))
    return nil
}
indexForKey[key] = index

At the moment of writing InsertionOrderedDictionaryTests don't have tests for updateValue.

The following test triggers the assertion:

func test_updateValue() {
    var d0 = p0
    for (key, value) in p1 {
        XCTAssertEqual(d0[key], value)
        let replaced = d0.updateValue("*", forKey: key)
        XCTAssertEqual(d0[key], "*")
        XCTAssertEqual(replaced, value)
    }
    XCTAssertEqual(d0[99], nil)
}
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

No branches or pull requests

1 participant