[stdlib] Document that put and add keep the stored key or element - #7643
Conversation
Code Owners
PR commands for maintainers
|
|
/dry-run |
There was a problem hiding this comment.
Pull request overview
Documents that mutable maps and sets retain existing key/element instances when equal instances are added.
Changes:
- Expands collection API documentation across platforms.
- Adds executable samples demonstrating identity retention.
- Adds cross-implementation regression tests.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
libraries/stdlib/test/collections/StoredKeyIdentityTest.kt |
Tests identity retention for maps, sets, and builders. |
libraries/stdlib/src/kotlin/collections/Maps.kt |
Links indexed assignment to put. |
libraries/stdlib/src/kotlin/Collections.kt |
Documents common add, addAll, put, and putAll behavior. |
libraries/stdlib/samples/test/samples/collections/maps.kt |
Adds a stored-key sample. |
libraries/stdlib/samples/test/samples/collections/collections.kt |
Adds a stored-element sample. |
libraries/stdlib/native-wasm/src/kotlin/collections/Set.kt |
Updates Native/Wasm set contracts. |
libraries/stdlib/native-wasm/src/kotlin/collections/Map.kt |
Updates Native/Wasm map contracts. |
libraries/stdlib/native-wasm/src/kotlin/collections/AbstractMutableSet.kt |
Documents abstract set behavior. |
libraries/stdlib/native-wasm/src/kotlin/collections/AbstractMutableMap.kt |
Documents abstract map behavior. |
libraries/stdlib/jvm/src/kotlin/collections/AbstractMutableSet.kt |
Documents JVM abstract set behavior. |
libraries/stdlib/jvm/src/kotlin/collections/AbstractMutableMap.kt |
Documents JVM abstract map behavior. |
libraries/stdlib/jvm/builtins/Collections.kt |
Updates JVM built-in collection contracts. |
libraries/stdlib/js/builtins/Collections.kt |
Updates JS built-in collection contracts. |
libraries/stdlib/common/src/kotlin/collections/AbstractMutableMap.kt |
Updates the common abstract map contract. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
THIS IS A DRY RUN Quality gate is triggered at https://buildserver.labs.intellij.net/build/1038193983 — use this link to get full insight. Quality gate was triggered with the following revisions:
Quality gate finished successfully. |
| * @return the previous value associated with the key, or `null` if the key was not present in the map. | ||
| * | ||
| * @sample samples.collections.Maps.CoreApi.put | ||
| * @sample samples.collections.Maps.CoreApi.putKeepsStoredKey |
There was a problem hiding this comment.
I don't think it deserves a separate sample or even a sample at all.
| /** | ||
| * Associates the specified [value] with the specified [key] in the map. | ||
| * | ||
| * If the map already contains a mapping for [key], the key instance stored in the map is retained. |
There was a problem hiding this comment.
I would rather say what happens with the value, it would be more useful from the user perspective.
| * If the map already contains a mapping for [key], the key instance stored in the map is retained. | |
| * If the map already contains a mapping for [key], the value for that key is replaced with the specified [value]. |
^KT-88708 Fixed