feat(dummies): add ContainingEntry to pin a dictionary entry's value#290
Merged
Conversation
ContainingKey(TKey) forces a key in, but its value was still drawn arbitrarily from the value generator, so a test could not pin a specific key/value pair. Unlike the other containment methods this needed new state: keys flow through CollectionState, whereas values are generated per key. Add ContainingEntry(TKey, TValue): it forces the key in exactly as ContainingKey does (inheriting the out-of-domain cardinality credit) and records key -> value in an immutable, comparer-aware map that Generate consults before falling back to the value generator; With carries the map across later constraints. A duplicate key — two entries, or an entry and a ContainingKey for the same key — conflicts eagerly through the existing distinct-key validation, so no new conflict rule is introduced. The factory keeps its three-argument constructor, which now delegates to a private four-argument one, so Any.DictionaryOf is untouched. Declare it in both per-TFM PublicAPI baselines and cover it with tests: the pinned value surfacing with an out-of-domain key, and the duplicate-key conflict. Refs: #288 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018RduXUaM3V6tk6MuKxzVzJ
Reefact
force-pushed
the
claude/issue-288-containing-entry
branch
from
July 22, 2026 15:32
b16abc7 to
7003330
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AnyDictionary.ContainingKey(TKey)forces a key into the generated dictionary, but its value was still drawn arbitrarily from the value generator — so a test could not pin a specific key/value pair. This addsContainingEntry(TKey, TValue), which pins the value for a required key while leaving the other entries arbitrary.Closes #288. The method name (
ContainingEntry, overContaining(TKey, TValue)or a chainedContainingKey(...).WithValue(...)) was chosen with the maintainer.Type of change
Changes
AnyDictionary.ContainingEntry(TKey key, TValue value): it forces the key in exactly asContainingKeydoes (so it inherits the out-of-domain cardinality credit) and recordskey → valuein an immutable, comparer-aware map thatGenerate()consults before falling back to the value generator.With(...)carries the map across later constraints, keeping the recipe immutable.ContainingKeyfor the same key — fails eagerly withConflictingAnyConstraintExceptionthrough the key-distinctness validation already inCollectionState.Any.DictionaryOfis untouched.PublicAPI.Unshipped.txtbaselines (netstandard2.0andnet8.0).ContainingKeyforms).Testing
dotnet build FirstClassErrors.sln— Build succeeded, 0 Warning(s), 0 Error(s) (both thenetstandard2.0andnet8.0legs of Dummies; the PublicAPI analyzer is clean).dotnet test FirstClassErrors.sln— full suite not run locally; randotnet test Dummies.UnitTestsinstead: 453 passed (2 new), 0 failed, 0 skipped.FirstClassErrors.Analyzers.UnitTests) — not run; no analyzer change in this PR.Documentation
PublicAPI.*.txtbaselines.doc/updateddoc/handwritten/for-users/README.fr.md) updated if user-facing behavior changedArchitecture decisions
Proposed: ADR-____Related issues
Closes #288.