Skip to content

Commit 3e73414

Browse files
xperiandriclaude
andcommitted
fixup! feat: FrozenMap module with the vocabulary of the FSharp.Core Map module
`yield!` of an array of struct pairs and of a frozen map in `frozenMap { }` had no check, so a `null` input failed with `NullReferenceException` when the buffer enumerated it, inside `Run`. The two members now throw `ArgumentNullException` that names the parameter (`pairs`, `table`) when the expression runs them, as `yield!` of a sequence does (ADR 0001, D6), and their `<exception>` tags say so. The other inputs of `FrozenMapCE` need no check: they are functions that the compiler creates from the expression, and the resource of `use`, which F# accepts as `null`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 747d98c commit 3e73414

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

‎src/FSharp.Collections.Immutable/FrozenMap/FrozenMapCE.fs‎

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

3737
member inline _.YieldFrom (pairs : struct ('Key * 'Value) array) : FrozenMapBuffer<'Key, 'Value> =
38+
// A null array fails with NullReferenceException when the buffer enumerates it; the expression rejects it when
39+
// yield! runs, as it does a null sequence (ADR 0001, D6)
40+
checkNotNull (nameof pairs) pairs
41+
3842
fun bindings ->
3943
for struct (key, value) in pairs do
4044
bindings[key] <- value
@@ -47,6 +51,8 @@ type FrozenMapCE<'Key when 'Key : not null> (keyComparer : IEqualityComparer<'Ke
4751
bindings[pair.Key] <- pair.Value
4852

4953
member inline _.YieldFrom (table : FrozenMap<'Key, 'Value>) : FrozenMapBuffer<'Key, 'Value> =
54+
checkNotNull (nameof table) table
55+
5056
fun bindings ->
5157
for pair in table do
5258
bindings[pair.Key] <- pair.Value

‎src/FSharp.Collections.Immutable/FrozenMap/FrozenMapCE.fsi‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type FrozenMapCE<'Key when 'Key : not null> =
7575
/// <summary>
7676
/// Sets the bindings of an array of struct pairs.
7777
/// </summary>
78+
/// <exception cref="T:System.ArgumentNullException">Thrown when the array is <see langword="null"/>.</exception>
7879
/// <remarks>
7980
/// A value replaces the value of an earlier binding of its key, whose key stays (ADR 0001, D14).
8081
/// </remarks>
@@ -92,6 +93,7 @@ type FrozenMapCE<'Key when 'Key : not null> =
9293
/// <summary>
9394
/// Sets the bindings of a frozen map.
9495
/// </summary>
96+
/// <exception cref="T:System.ArgumentNullException">Thrown when the frozen map is <see langword="null"/>.</exception>
9597
/// <remarks>
9698
/// A value replaces the value of an earlier binding of its key, whose key stays (ADR 0001, D14).
9799
/// </remarks>

0 commit comments

Comments
 (0)