Quantcast
Channel: YouTrackReSharper (RSRP) - Bug and Issue Tracker
Viewing all articles
Browse latest Browse all 106942

RSRP-469149: Class 'this' is immutable" when assigning readonly field inside readonly struct constructor via "this.Field"

$
0
0
Reporter Olga Rodygina (olgarodygina) Olga Rodygina (olgarodygina)
Created Apr 6, 2018 6:34:24 PM
Updated Apr 6, 2018 6:34:33 PM
Subsystem Code Analysis
Assignee Ivan Serduk (IvanSerduk)
Priority Normal
State Submitted
Type Bug
Fix version No Fix versions
Affected versions No Affected versions
Fixed In Version ReSharper Undefined
VsVersion All Versions
Just upgraded to R# 2018.1 EAP 6 (and VS 2017 15.6.5) and I'm now getting intellisense errors when assigning readonly fields inside the constructor of a "readonly struct".

If I change "readonly struct" to a regular "struct" (but keep the field readonly) the error goes away.

If I keep "readonly struct" but replace "this.Id = id" by just "Id = id" then the error also goes away.

–FAIL
public readonly struct Foo 
{
public readonly string Id;

public Foo(string id)
{
this.Id = id; // ERROR: "Class 'this' is immutable. Cannot modify struct members when accessed struct is not classified as a variable"
}
}

–OK
public struct Foo // not readonly 
{
public readonly string Id;

public Foo(string id)
{
this.Id = id; // OK
}
}


–OK
–FAIL
public readonly struct Foo // readonly 
{
public readonly string Id;

public Foo(string id)
{
Id = id; // OK
}
}

Viewing all articles
Browse latest Browse all 106942

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>