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
Product and Version Used: Roslynator.Analyzers4.12.2
Steps to Reproduce:
Expose a backing field used as an in-parameter with a property.
Actual Behavior:
usingSystem.Buffers;classRepro(ReadOnlySequence<byte>data){// v RCS1085: use auto-implemented propertypublicReadOnlySequence<byte>Data=>_data;privatereadonlyReadOnlySequence<byte>_data=data;publicvoidMethod(IBufferWriter<byte>writer){Write1(in_data,writer);Write2(in_data,writer);}privatestaticvoidWrite1(inReadOnlySequence<byte>data,IBufferWriter<byte>writer){data.CopyTo(writer.GetSpan((int)data.Length));}privatestaticvoidWrite2(refreadonlyReadOnlySequence<byte>data,IBufferWriter<byte>writer){data.CopyTo(writer.GetSpan((int)data.Length));}}
Auto-fixer changes usages to Write1(in this.Data, writer), which correctly is then flagged as an error:
CS8156 An expression cannot be used in this context because it may not be passed or returned by reference
Expected Behavior:
No diagnostic should be reported.
As far as I know, there's no way of using a property return value with in without a backing field. This diagnostic seems to be reliant on _data being readonly, as removing the modifer silences RCS1085 (and then correctly raises IDE0044 Make field readonly). Making the backing field anything else than private also suppresses the warning.
I can try to take a crack at this with some direction. Does there exist a neat built-in way in Roslynator to find all usages of the field?
The text was updated successfully, but these errors were encountered:
Product and Version Used:
Roslynator.Analyzers
4.12.2
Steps to Reproduce:
Expose a backing field used as an
in
-parameter with a property.Actual Behavior:
Auto-fixer changes usages to
Write1(in this.Data, writer)
, which correctly is then flagged as an error:CS8156 An expression cannot be used in this context because it may not be passed or returned by reference
Expected Behavior:
No diagnostic should be reported.
As far as I know, there's no way of using a property return value with
in
without a backing field. This diagnostic seems to be reliant on_data
beingreadonly
, as removing the modifer silences RCS1085 (and then correctly raises IDE0044 Make field readonly). Making the backing field anything else thanprivate
also suppresses the warning.I can try to take a crack at this with some direction. Does there exist a neat built-in way in Roslynator to find all usages of the field?
The text was updated successfully, but these errors were encountered: