reactiveui / ReactiveUI.SourceGenerators

Use source generators to generate objects.
MIT License
25 stars 1 forks source link

[Bug]: null values handling with OAPH ToProperty #63

Open Geccoka opened 4 days ago

Geccoka commented 4 days ago

Describe the bug 🐞

Having an IObservable<EventSpeaker> CurrentSpeaker observable to which i subscribe like this:

CurrentSpeaker
    .ToProperty(this, x => x.CurrentSpeaker, out _currentSpeakerHelper)
    .DisposeWith(_compositeDisposable);

After a speaker has spoken this observable will send a NULL value to its subscribers.

I am migrating away from Fody to the new source generators, and have an issue with this use case. The generated code for the CurrentSpeaker is:

public global::EventSpeaker CurrentSpeaker { get => _currentSpeaker = (_currentSpeakerHelper?.Value ?? _currentSpeaker); }

The problem is that the _currentSpeakerHelper.Value is null and the _currentSpeaker contains the previous value and because of the ?? operator the previous value will be provided and not the null.

This issue was introduced in #28 i think.

Expected behavior

The null value should be set for the generated property.

ChrisPulman commented 2 days ago

Thank you for this, the intended was to catch the point when _currentSpeakerHelper was null and return the default value, otherwise return the _currentSpeakerHelper.Value, I will update the code to achieve the desired operation as this is also the intended way originally intended.