Skip to content

Commit 6fc99a0

Browse files
xperiandriclaude
andcommitted
fixup! feat: HashMap and IMap modules with the vocabulary of the FSharp.Core Map module
`yield!` of an array of struct pairs and of a hash map had no null check: a `null` array or map failed with `NullReferenceException` when the buffer ran, and not as `ArgumentNullException` that names `pairs` or `table` when the member runs, as the overloads for sequences do. Both members now call `checkNotNull` first, and the signature file documents the exception. The other members of `HashMapCE` take a struct (`Yield`), a function value of the expression (`YieldFrom` of a buffer, `Combine`, `Delay`, `While`, `TryWith`, `TryFinally`, `Using`) or the sequence that is already checked (`YieldFrom`, `For`), as in `FlatListCE`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 0e2bb7d commit 6fc99a0

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

‎src/FSharp.Collections.Immutable/HashMap/HashMapCE.fs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ type HashMapCE<'Key when 'Key : not null> (keyComparer : IEqualityComparer<'Key>
3535
builder[key] <- value
3636

3737
member inline _.YieldFrom (pairs : struct ('Key * 'Value) array) : HashMapBuffer<'Key, 'Value> =
38+
// A null array fails when the buffer runs; the expression rejects it when yield! runs, as it rejects a sequence
39+
checkNotNull (nameof pairs) pairs
40+
3841
fun builder ->
3942
for struct (key, value) in pairs do
4043
builder[key] <- value
@@ -47,6 +50,9 @@ type HashMapCE<'Key when 'Key : not null> (keyComparer : IEqualityComparer<'Key>
4750
builder[pair.Key] <- pair.Value
4851

4952
member inline _.YieldFrom (table : HashMap<'Key, 'Value>) : HashMapBuffer<'Key, 'Value> =
53+
// A null hash map fails when the buffer runs; the expression rejects it when yield! runs, as it rejects a sequence
54+
checkNotNull (nameof table) table
55+
5056
fun builder ->
5157
for pair in table do
5258
builder[pair.Key] <- pair.Value

‎src/FSharp.Collections.Immutable/HashMap/HashMapCE.fsi‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type HashMapCE<'Key when 'Key : not null> =
7777
/// <summary>
7878
/// Sets the bindings of an array of struct pairs.
7979
/// </summary>
80+
/// <exception cref="T:System.ArgumentNullException">Thrown when the array is <see langword="null"/>.</exception>
8081
/// <remarks>
8182
/// A value that the default comparer of the values finds equal to the value of an earlier binding of the key keeps the
8283
/// earlier binding, its key included (ADR 0001, D14).
@@ -96,6 +97,7 @@ type HashMapCE<'Key when 'Key : not null> =
9697
/// <summary>
9798
/// Sets the bindings of a hash map.
9899
/// </summary>
100+
/// <exception cref="T:System.ArgumentNullException">Thrown when the hash map is <see langword="null"/>.</exception>
99101
/// <remarks>
100102
/// A value that the default comparer of the values finds equal to the value of an earlier binding of the key keeps the
101103
/// earlier binding, its key included (ADR 0001, D14).

0 commit comments

Comments
 (0)