You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the explicit implementations are not marked as readonly, the compiler must assume they can mutate, and therefore should create a defensive copy before calling GetEnumerable.
Actual Behavior:
The compiler doesn't recognise that it needs to create a defensive copy, and thus at the point of foreach, it can mutate the readonly reference.
The text was updated successfully, but these errors were encountered:
Version Used:
Steps to Reproduce:
IEnumerable<T>
explicitly on a struct, and do not mark the implementations asreadonly
GetEnumerable
implementationref readonly
orin
parameter of your typeMinimal repro:
https://sharplab.io/#v2:EYLgtghglgdgNAFxAJwK4wD4AEBMBGAWACgsAGAAizwDoBhAewBtGBTAYwSnpgGcBuYmUp4ALAJIUq1ADKwAjuMEBmSjnK1iAb2LldqnDr3aie0+QDK5AG4RGqFuQC85GCwDuACgCU4s3uQsAGbkARAAJtyMAJ4W1rb2AEpBTiHJNnYsvn7CAJwe6YlBPoZ+ALIesHEZSYHFJtlUeQUsNXWmAL4llCpUAGyUIuTllZbNXl3G2eQA9NMAkjw89uRQPOQIABYOmw5s9GAADlCsyOQRLDwwAOQI5DwsLGDr9ORsW2wA1iuBXaazVEoADywBAAPmoAHEWAgAKIwVBgFjICAIeinVbkSDID4sMLkCBrUIRGDRai/PSBNEsCBvcj5CCnAAeKxgVXsXnImnInXquh5POUdwQaA4sRAwiBINBWi6IPxWV0WBURMiMXoViRyCgYQcVAoABV6OZhbAAObeJyg/HUQ3GrUwc1tPQHLU2BAOOZwhFIlFo4EwMHkKGw+GI5Go5AWxxWr1hiDAVjUBIQB0sDykODkADUWYgXkh0NjPoj3gV5E9oeLfqlEv9YILIe94bRUatwaLzcjTt0FabvtOAIbHf7raDhcrndLxB5QA
Expected Behavior:
Since the explicit implementations are not marked as
readonly
, the compiler must assume they can mutate, and therefore should create a defensive copy before callingGetEnumerable
.Actual Behavior:
The compiler doesn't recognise that it needs to create a defensive copy, and thus at the point of
foreach
, it can mutate the readonly reference.The text was updated successfully, but these errors were encountered: