Allow invoking readonly members on structs in object initializers #8427
Replies: 3 comments 46 replies
-
This seems like a case for |
Beta Was this translation helpful? Give feedback.
-
This code doesn't make sense to me. Numbers property is a getter for a ref struct. How would you even be able to write that to a class? It's illegal even without CS1918. It seems that you would want to have a collection expression work by adding elements to an existing collection, rather than creating a new one. I don't think that even makes sense with the assignment operator, and maybe needs something like a backward pipe operator |
Beta Was this translation helpful? Give feedback.
-
It's a different error, but it seems very closely related to #9174. @jnm2 [Edit] Ah, I see it was called out in #9175. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Imagine you have a lazy-instantiated collection, and a "proxy collection" to wrap around it:
The gist of it is, the CS1918 shouldn't be generated, because the
Wrapper.Add
isreadonly
, therefore it's safe to invoke it as part of collection initializer. CS1918 should continue to be generated in all other existing cases.Beta Was this translation helpful? Give feedback.
All reactions