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

We don't need to report about mutability for a readonly field with no assignments #721

Open
j3parker opened this issue Mar 9, 2021 · 2 comments

Comments

@j3parker
Copy link
Member

j3parker commented Mar 9, 2021

If a tree falls in the woods and no one is around to hear it, does it make a sound? It does not.

public class Foo {
  protected readonly object m_whatever;
}

There is no mutability here, because there are no writes to m_whatever (protected readonly can't be set from derived constructors). It is the same as:

public class Foo {
  protected readonly object m_whatever = null;
}

which we have always shrugged at.

It would be a minor simplification of the code to not report a diagnostic here, and it'd be more consistent.

(That doesn't mean it's realistic, and ideally another diagnostic fires for this code (indeed there are built-in ones))

@j3parker
Copy link
Member Author

Although this would be a good move it is a substantial behaviour change in which diagnostics we report, and this will have a big impact on the test suite.

It means that the tests will need to have writes to each member that is supposed to be bad, which of course requires many changes. However, when we do identify writes we prefer placing diagnostics on the writes rather than on the field type itself. So by modifying the tests to have writes we're also making those diagnostics not show up on the members.

It will be a big change to the tests file, but we should re-evaluate where exactly we want our diagnostics. Perhaps this change would be OK.

@j3parker
Copy link
Member Author

j3parker commented Apr 8, 2021

Counterpoint: this did indirectly highlight the bug #738

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant