Observable property attribute with negative enum values gives cast error #731
Labels
analyzer 👓
A new analyzer being implemented or updated
bug 🐛
An unexpected issue that highlights incorrect behavior
mvvm-toolkit 🧰
Issues/PRs for the MVVM Toolkit
Describe the bug
After updating my project that as an observable property with a negative enum attribute to version 8.2.1, I still have an error when I try to use the enum. As a workaround I've been using a literal value to suppress the error.
Before, in version 8.2.0, the source generators stopped working. In version 8.2.1 it gives the errors:
This bug can be easily reproduced with the code below.
Regression
No response
Steps to reproduce
This bug occurred when I tested in .NET 7 in a WPF project with both Visual Studio 17.6.4 and 17.7.0 Preview 2.0 and the latest CommunityToolkit.Mvvm 8.2.1. It probably would happen with other versions.
Using the following code the bug can be reproduced:
Changing the default value for _test3 to NegativeEnum.OK will allow the code to compile without errors, changing back to NegativeEnum.Problem and the errors described above occur.
Also note that if using the NegativeEnum.Problem, removing the 'property:' before the DefaultValueAttribute doesn't seem to have the problem. It only occurs for attributes passed to the property generated.
Expected behavior
An enum with a negative value in a property attribute shouldn't give a cast error.
Screenshots
No response
IDE and version
VS 2022, VS 2022 Preview
IDE version
17.6.4, 17.7.0 Preview 2.0
Nuget packages
Nuget package version(s)
8.2.1
Additional context
This is a continuation of the problem reported in issue #681.
Help us help you
No, just wanted to report this
The text was updated successfully, but these errors were encountered: