Repository navigation
Catch deconstruction ref escape errors in invocation escape analysis - #64470
Conversation
5cef066 to
3d637b3
Compare
| [Theory] | ||
| [InlineData(LanguageVersion.CSharp10)] | ||
| [InlineData(LanguageVersion.CSharp11)] | ||
| public void Deconstruct_11(LanguageVersion languageVersion) |
There was a problem hiding this comment.
Deconstruct_09, _10, _11 test var deconstruction declarations which should be addressed by #64414.
|
@dotnet/roslyn-compiler, please review, thanks. |
| var source = | ||
| @"ref struct R1 | ||
| { | ||
| public R1(ref int i) { } |
There was a problem hiding this comment.
Consider having the constructor look like this
public R1(Span<int> span) { }#Resolved
There was a problem hiding this comment.
Removed test. The Span<int> case is covered in 4A.
| static void F1() | ||
| { | ||
| int i = 1; | ||
| var r = new R1(ref i); |
There was a problem hiding this comment.
Then here do the following:
var r = new R1(stackalloc int[42]);Together those two changes will make the errors uniform through the language versions. #Resolved
There was a problem hiding this comment.
The new tests include a number of Span<int> / stackalloc tests to test that the errors are uniform across language versions. For these tests, I was interested in the differences between language versions as well.
There was a problem hiding this comment.
Removed 2A and 2B (the equivalent Span<int> cases were 4A and 4B).
| [Theory] | ||
| [InlineData(LanguageVersion.CSharp10)] | ||
| [InlineData(LanguageVersion.CSharp11)] | ||
| public void Deconstruct_02B(LanguageVersion languageVersion) |
There was a problem hiding this comment.
Same feedback here. #Resolved
| [Theory] | ||
| [InlineData(LanguageVersion.CSharp10)] | ||
| [InlineData(LanguageVersion.CSharp11)] | ||
| public void Deconstruct_05(LanguageVersion languageVersion) |
There was a problem hiding this comment.
Same feedback here. #Resolved
There was a problem hiding this comment.
Removed 5 (the equivalent Span<int> case was 6).
| } | ||
| ref struct R2 | ||
| { | ||
| public R2(ref int i) { } |
| [Theory] | ||
| [InlineData(LanguageVersion.CSharp10)] | ||
| [InlineData(LanguageVersion.CSharp11)] | ||
| public void Deconstruct_02B(LanguageVersion languageVersion) |
There was a problem hiding this comment.
Nit: could almost just use [InlineData(LanguageVersion.CSharp10, "Span<int>")] + a few more entries and just combine with the test above. #Resolved
There was a problem hiding this comment.
I'd considered combining with the previous test - either with a Span<int> parameter to the test method, or having two methods in the test, one for Span<int> and one for ReadOnlySpan<int> - but two separate test methods seemed easy to read.
| int x2; | ||
| int i = 2; | ||
| R y2 = new R(ref i); | ||
| (x2, y2) = s; |
There was a problem hiding this comment.
| (x2, y2) = s; | |
| (x2, y2) = s; // 3 |
and update tests accordingly.
Again though, feel like this is just making it look like there are big differences for deconstruct between lang versions. Every one of these tests I have to approach with
Wait, why did language rules around deconstruct change between 10 and 11?
In reality they're no different at all. #Resolved
| static void Deconstruct(this Span<int> s, out R2 x, out R1 y) => throw null; | ||
| }"; | ||
| var comp = CreateCompilationWithSpanAndMemoryExtensions(source, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion)); | ||
| if (languageVersion == LanguageVersion.CSharp10) |
There was a problem hiding this comment.
Aren'd the diagnostics in the if and else the same here. #Resolved
There was a problem hiding this comment.
The parameter in the ERR_CallArgMixing diagnostic is different: x vs. this.
|
|
||
| Conversion conversion; | ||
| // Among other things, MakeDeconstructionConversion() will handle | ||
| // value escape analysis for the Deconstruct() method group. |
There was a problem hiding this comment.
note that this escape analysis eventually occurs through the already existing call to BindMethodGroupInvocation on the synthesized Deconstruct call.
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
Fixes #64000
The first commit contains tests only, no compiler changes.