Skip to content

Commit

Permalink
Fixed a bogus use of the default keyword, within a ternary expressi…
Browse files Browse the repository at this point in the history
…on 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)
  • Loading branch information
JakenVeina authored Aug 16, 2024
1 parent 41a608d commit afbbb47
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/DynamicData.Tests/Cache/TransformImmutableFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,26 @@ public void TransformFactoryThrows_ExceptionIsCaptured()
results.IsCompleted.Should().BeFalse();
}

// https://github.com/reactivemarbles/DynamicData/issues/925
[Fact]
public void TDestinationIsValueType_DoesNotThrowException()
{
using var source = new Subject<IChangeSet<string, string>>();

using var results = source
.TransformImmutable(transformFactory: static value => value.Length)
.AsAggregator();


source.OnNext(new ChangeSet<string, string>()
{
new(reason: ChangeReason.Add, key: "Item #1", current: "Item #1", index: 0)
});

results.Error.Should().BeNull();
results.Messages.Count.Should().Be(1, "1 source operation was performed");
}

private class Item
{
public static readonly Func<Item, int> IdSelector
Expand Down
4 changes: 3 additions & 1 deletion src/DynamicData/Cache/Internal/TransformImmutable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Reactive;
using System.Reactive.Linq;

using DynamicData.Kernel;

namespace DynamicData.Cache.Internal;

internal sealed class TransformImmutable<TDestination, TSource, TKey>
Expand Down Expand Up @@ -40,7 +42,7 @@ public IObservable<IChangeSet<TDestination, TKey>> Run()
current: _transformFactory.Invoke(change.Current),
previous: change.Previous.HasValue
? _transformFactory.Invoke(change.Previous.Value)
: default,
: Optional.None<TDestination>(),
currentIndex: change.CurrentIndex,
previousIndex: change.PreviousIndex));
}
Expand Down

0 comments on commit afbbb47

Please sign in to comment.