-
Notifications
You must be signed in to change notification settings - Fork 351
Open
Labels
bug 🐛An unexpected issue that highlights incorrect behaviorAn unexpected issue that highlights incorrect behavior
Description
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
Metadata
Metadata
Assignees
Labels
bug 🐛An unexpected issue that highlights incorrect behaviorAn unexpected issue that highlights incorrect behavior