Skip to content

Commit afbbb47

Browse files
authoredAug 16, 2024··
Fixed a bogus use of the default keyword, within a ternary expression where implicit casting of a generic is in play. The expression compiles differently depending on whether the generic type in question is a value type, versus a reference type, and generates an excpetion in the case of a value type. (#926)
1 parent 41a608d commit afbbb47

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

‎src/DynamicData.Tests/Cache/TransformImmutableFixture.cs

+20
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,26 @@ public void TransformFactoryThrows_ExceptionIsCaptured()
267267
results.IsCompleted.Should().BeFalse();
268268
}
269269

270+
// https://github.com/reactivemarbles/DynamicData/issues/925
271+
[Fact]
272+
public void TDestinationIsValueType_DoesNotThrowException()
273+
{
274+
using var source = new Subject<IChangeSet<string, string>>();
275+
276+
using var results = source
277+
.TransformImmutable(transformFactory: static value => value.Length)
278+
.AsAggregator();
279+
280+
281+
source.OnNext(new ChangeSet<string, string>()
282+
{
283+
new(reason: ChangeReason.Add, key: "Item #1", current: "Item #1", index: 0)
284+
});
285+
286+
results.Error.Should().BeNull();
287+
results.Messages.Count.Should().Be(1, "1 source operation was performed");
288+
}
289+
270290
private class Item
271291
{
272292
public static readonly Func<Item, int> IdSelector

‎src/DynamicData/Cache/Internal/TransformImmutable.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using System.Reactive;
66
using System.Reactive.Linq;
77

8+
using DynamicData.Kernel;
9+
810
namespace DynamicData.Cache.Internal;
911

1012
internal sealed class TransformImmutable<TDestination, TSource, TKey>
@@ -40,7 +42,7 @@ public IObservable<IChangeSet<TDestination, TKey>> Run()
4042
current: _transformFactory.Invoke(change.Current),
4143
previous: change.Previous.HasValue
4244
? _transformFactory.Invoke(change.Previous.Value)
43-
: default,
45+
: Optional.None<TDestination>(),
4446
currentIndex: change.CurrentIndex,
4547
previousIndex: change.PreviousIndex));
4648
}

0 commit comments

Comments
 (0)
Please sign in to comment.