CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
3.07k stars 299 forks source link

Forwarded attributes can crash generator when accessing invalid members #683

Closed Sergio0694 closed 1 year ago

Sergio0694 commented 1 year ago

Describe the bug

The forwarded attribute logic (for both observable properties and relay commands) can crash the generator in some invalid scenarios. We should instead emit a proper diagnostic and gracefully skip the current attribute, rather than crashing the generator.

Steps to reproduce

public partial class Foo : ObservableObject
{
    [ObservableProperty]
    [property: Test(TestAttribute.M)]
    private int number;
}

public class TestAttribute : Attribute
{
    public static string M => "";
}

Expected behavior

This should skip the attribute and generate a diagnostic.