Skip to content

Make it an error to invoke non-readonly methods on a readonly field #8355

Discussion options

You must be logged in to vote

There is nothing wrong calling a non-readonly method on a readonly field. Indeed, it's super common. Consider how often people may call things like GetHashCode, ToString, or even Equals on these methods. All of which are not commonly exported as something readonly.

These issues are currently solved by analyzers

Yes, this is the right way to do things. Having the language fail here would break everything.

Replies: 1 comment 100 replies

Comment options

You must be logged in to vote
100 replies
@TahirAhmadov
Comment options

@TahirAhmadov
Comment options

@TahirAhmadov
Comment options

@CyrusNajmabadi
Comment options

@CyrusNajmabadi
Comment options

Answer selected by CyrusNajmabadi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
7 participants