Skip to content

Properties generated from private fields do not conflict/trigger CS0108 or any other warning #1092

@bzd3y

Description

@bzd3y

Describe the bug

Given two types, where one is derived from the other, adding a private field to the derived type with the same name as a private field on the base type will generate a property on each type's generated partial definition. Because code analysis is disabled on these generated files, no indication is given that the property on the derived type is hiding the property on the base type.

Regression

No response

Steps to reproduce

The following code should demonstrate the problem:

public class TypeA : ObservableObject
{
    [ObservableProperty]
    private bool _someField; // will generate TypeA.SomeField
}

public class TypeB : TypeA
{
    [ObservableProperty]
    private bool _someField; // will generate TypeB.SomeField, hiding TypeA.SomeField
}

Expected behavior

Some indication should be given that TypeB._someField causes hiding of the property generated for TypeA, either CS0108 on the field or some MVVM specific warning that explains exactly what is happening.

Screenshots

No response

IDE and version

VS 2022

IDE version

17.13.6

Nuget packages

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

Nuget package version(s)

8.4.0

Additional context

No response

Help us help you

No, just wanted to report this

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛An unexpected issue that highlights incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions