Skip to content

[Bug]: Nullable partial properties with ObservableAsProperty are not updated with null value #197

@X3oNZ

Description

@X3oNZ

Describe the bug 🐞

Source Generator for nullable partial ObservableAsProperty emits code that won't allow value to be updated with null value; while the last non-null value remains.

Step to reproduce

Property:

[ObservableAsProperty]
public partial string? Test { get; }

Generated Code:

private string? _test;

private readonly ReactiveUI.ObservableAsPropertyHelper<string?> _testHelper;

[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public partial string? Test { get => _test = _testHelper?.Value ?? _test; }

In above case value is updated and .ToProperty is called with null value; value is not updated and previous non-null value remains.

Reproduction repository

https://github.com/reactiveui/ReactiveUI

Expected behavior

Expected code generation for nullable property should be:

private string? _test;

private readonly ReactiveUI.ObservableAsPropertyHelper<string?> _testHelper;

[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public partial string? Test { get => _test = _testHelper?.Value; }

Screenshots 🖼️

No response

IDE

Visual Studio 2022

Operating system

Windows

Version

2.1.8

Device

No response

ReactiveUI Version

20.1.63

Additional information ℹ️

The above provided bug may not evet be a bug but expected behaviour. I encountered it while developing my application and property was behaving unexpectedly while being updated with null value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions