Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObserveableProperty and Nullable Can Generate Warnings #846

Open
1 of 4 tasks
david-maw opened this issue Feb 29, 2024 · 0 comments
Open
1 of 4 tasks

ObserveableProperty and Nullable Can Generate Warnings #846

david-maw opened this issue Feb 29, 2024 · 0 comments
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior

Comments

@david-maw
Copy link

Describe the bug

An observable property in a nullable class like the one shown here can cause somewhat intractable warnings.

using CommunityToolkit.Mvvm.ComponentModel;
using System.Diagnostics.CodeAnalysis;

namespace ObservableTest;

internal partial class TestViewModel:ObservableObject
{
    TestViewModel() 
    {
        Helper();
    }

    [MemberNotNull(nameof(testString))]
    private void Helper()
    {
        TestString = string.Empty;
    }

    [ObservableProperty]
    private string testString;
}

Regression

No response

Steps to reproduce

Create a default MAUI app and add a class like the one shown above.

Observe that the line:
    [MemberNotNull(nameof(testString))]

Gets a warning for referring to testString, not TestString, but referring to TestString generates a different warning (CS8618: Non-nullable field 'testString' must contain a non-null value when exiting constructor)

Expected behavior

Either don't warn on this use of testString or allow TestString to be used here.

Screenshots

No response

IDE and version

VS 2022 Preview

IDE version

17.10.0 Preview 1

Nuget packages

  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.2.2

Additional context

No response

Help us help you

No, just wanted to report this

@david-maw david-maw added the bug 🐛 An unexpected issue that highlights incorrect behavior label Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior
Projects
None yet
Development

No branches or pull requests

1 participant