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
Missing "CS8656: Call to non-readonly member from a 'readonly' member results in an implicit copy of 'this'" warning on inner field method calls
#36794
Closed
controlflow opened this issue
Jun 26, 2019
· 3 comments
struct A {
int X;
public void Incr() => X++;
public readonly void Readonly() {
Incr(); // CS8656: Call to non-readonly member 'I.Incr()' from a 'readonly' member results in an implicit copy of 'this'.
}
}
struct B {
A _inner;
public readonly void Readonly() {
_inner/*copy*/.Incr(); // Missing CS8656
}
public void Mutable() {
_inner.Incr();
}
}
key bit, which I really should place more prominently in that issue:
Note that we've decided to give a warning out of the box when a non-readonly member is called from a readonly member and the receiver is this. Implicit copy warnings on fields will only be handled by this warning wave, regardless of whether the copy is occurring due to the field being readonly or the containing method being readonly.
Version Used:
master branch 06/26/2019
Steps to Reproduce:
Compile the following code:
sharplab
Expected Behavior:
Compiler warning
Actual Behavior:
No warnings, field
_inner
being copied at runtime to preventthis
mutation.The text was updated successfully, but these errors were encountered: