Skip to content

Keep the stored key when ContiguousMap's indexer updates a value - #75

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/containers-69-map-indexer-keeps-key
Sep 26, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/containers-69-map-indexer-keeps-key

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #69

When the key already existed, ContiguousMap's indexer setter rebuilt the entry with the caller's key. With a normalising comparer, map["APPLE"] = 2 after map["Apple"] = 1 changed the key reported by Keys, enumeration and AsSpan() to "APPLE", while keyToIndex still held "Apple".

The setter now keeps the stored key and replaces only the value: new Entry(items[index].Key, value). Dictionary<,>, InsertionOrderMap and OrderedMap already behave this way.

Tests

  • Added Indexer_SetExistingKeyWithDifferentSpelling_KeepsOriginalKey. It uses StringComparer.OrdinalIgnoreCase and asserts that Keys, AsSpan() and enumeration all still report "Apple" with value 2.
  • I reverted the fix and ran the test again: it fails on Keys. With the fix it passes.
  • The full Containers.Test suite passes (390/390), and the Release build has no warnings.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YXTjHR3MfJpmxt8LEwNkjm


Generated by Claude Code

… [patch]

The indexer setter rebuilt the entry from the caller's key, so with a
normalising comparer an update through map["APPLE"] rewrote the key that
Keys, enumeration and AsSpan() report, while keyToIndex still held the
original. Keep the stored key and replace only the value, as Dictionary,
InsertionOrderMap and OrderedMap do.

Fixes #69

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YXTjHR3MfJpmxt8LEwNkjm
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 9ce2888 into main Sep 26, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the claude/containers-69-map-indexer-keeps-key branch September 26, 2026 23:49
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.

ContiguousMap indexer set on an existing key replaces the stored key with the caller's key

2 participants