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

Fix issue with incomplete property overrides in C# sourcegen #98396

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

paulloz
Copy link
Member

@paulloz paulloz commented Oct 21, 2024

This PR fixes a crash in several generators, preventing compilation through CS8785.

To filter read-only properties, we currently check if the property is read-only (duh), or is its set method is init-only. In reality, we cannot take for granted the fact a set method is available to check, even when the property is not read-only. This is because C# allows the following.

class Foo
{
    // Define a readable, and writable property as virtual
    public virtual string MyString
    {
        get;
        set;
    }
}

class Bar : Foo
{
    // Only override the get accessor
    public override string MyString
    {
        get { return "Gotcha"; }
    }
}

Since we assume we have a set method to check, we're raising an NRE when checking for the init-only flag. To fix this, we're now recursing on the overridden property if it makes sense.

Cheers ✌️

@paulloz paulloz added this to the 4.4 milestone Oct 21, 2024
@paulloz paulloz requested review from a team as code owners October 21, 2024 21:30
@paulloz paulloz removed the request for review from a team October 21, 2024 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.NET 6 C# - ScriptPropertiesGenerator fail with overridden initialized property on master
1 participant