morelinq / MoreLINQ

Extensions to LINQ to Objects
https://morelinq.github.io/
Apache License 2.0
3.63k stars 409 forks source link

`FillForward` bug when filler is `null` #999

Closed viceroypenguin closed 1 year ago

viceroypenguin commented 1 year ago

There is a slight bug in FillForward; though it is very obscure and unlikely to be relevant to most users.

Consider the following code:

var result = new int?[] { null, 200, null, }
    .FillForward(x => x == 200);

// expected
result == [ null, null, null ]

// actual
result == [ null, 200, null ]

The first value of null is not blank (null != 200); the second value is blank (200 == 200). Per the expectations of FillForward, the existing value of null should be carried forward to replace the 200 value. However, is (true, { } someSeed) rejects a null value, even if true, so we get the value of 200.

Related: viceroypenguin/SuperLinq#372

atifaziz commented 1 year ago

This is indeed super obscure and probably doesn't make practical sense, but it's a bug nonetheless so thanks for reporting it.