From 5a87250cb5ce6220080be785a70c92128b9b89b2 Mon Sep 17 00:00:00 2001 From: AlekseyTs Date: Fri, 13 Oct 2023 10:33:50 -0700 Subject: [PATCH 1/2] Rewrite captured field symbol during "materialization" (#70344) Fixes #70339. --- ...syncRewriter.CapturedSymbolOrExpression.vb | 2 +- .../MethodToClassRewriter.vb | 2 +- .../Test/Emit/CodeGen/CodeGenAsyncTests.vb | 147 ++++++++++++++++++ 3 files changed, 149 insertions(+), 2 deletions(-) diff --git a/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.CapturedSymbolOrExpression.vb b/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.CapturedSymbolOrExpression.vb index 19345c252fa82..28084c3bc3e88 100644 --- a/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.CapturedSymbolOrExpression.vb +++ b/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.CapturedSymbolOrExpression.vb @@ -154,7 +154,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic If Me.ReceiverOpt IsNot Nothing Then newReceiverOpt = Me.ReceiverOpt.Materialize(rewriter, Me.Field.ContainingType.IsValueType) End If - Return rewriter.F.Field(newReceiverOpt, Me.Field, isLValue) + Return rewriter.F.Field(newReceiverOpt, rewriter.VisitFieldSymbol(Me.Field), isLValue) End Function End Class diff --git a/src/Compilers/VisualBasic/Portable/Lowering/MethodToClassRewriter/MethodToClassRewriter.vb b/src/Compilers/VisualBasic/Portable/Lowering/MethodToClassRewriter/MethodToClassRewriter.vb index 861330cdcaf7d..741913fad7a2c 100644 --- a/src/Compilers/VisualBasic/Portable/Lowering/MethodToClassRewriter/MethodToClassRewriter.vb +++ b/src/Compilers/VisualBasic/Portable/Lowering/MethodToClassRewriter/MethodToClassRewriter.vb @@ -316,7 +316,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ''' ''' Rewrites field. ''' - Private Function VisitFieldSymbol(field As FieldSymbol) As FieldSymbol + Friend Function VisitFieldSymbol(field As FieldSymbol) As FieldSymbol Dim substitution As TypeSubstitution = Me.TypeMap If substitution IsNot Nothing Then diff --git a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenAsyncTests.vb b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenAsyncTests.vb index 361839c59f41b..1fad3233ded49 100644 --- a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenAsyncTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenAsyncTests.vb @@ -2930,6 +2930,153 @@ End Class , useLatestFramework:=True, expectedOutput:="0 2 3 4 5 1111 1") End Sub + + + Public Sub CapturingGenericField() + Dim comp = + + +Imports System.Threading.Tasks + +Structure Item(Of T) + Public Property Position(x As Integer) As Integer + Get + Return 0 + End Get + Set + End Set + End Property +End Structure + +Class Item2(Of T) + Public Item As Item(Of T) +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item2(Of Object)() + Call1(item1).Wait() + System.Console.Write("Done") + End Sub + + Private Shared Async Function Call1(Of T)(item As Item2(Of T)) As Task + item.Item.Position(await GetOffsetAsync()) += 1 + End Function + + Shared Async Function GetOffsetAsync() As Task(Of Integer) + await Task.Yield() + Return 0 + End Function +End Class + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:="Done").VerifyDiagnostics() + + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + ) + End Sub + Public Sub MeMyClassMyBase() CompileAndVerify( From be43d2e366df3a033c7974927f0af6c5a3f213b5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 13 Oct 2023 10:54:51 -0700 Subject: [PATCH 2/2] Disable flakey integration tests --- .../New.IntegrationTests/CSharp/CSharpGoToDefinition.cs | 2 +- .../New.IntegrationTests/VisualBasic/BasicGoToDefinition.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpGoToDefinition.cs b/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpGoToDefinition.cs index 690a8abf7d157..3e312b5de6761 100644 --- a/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpGoToDefinition.cs +++ b/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpGoToDefinition.cs @@ -167,7 +167,7 @@ public override string ToString() Assert.Equal(1, actual.Count(s => s.Collapsed)); } - [IdeFact] + [IdeFact(Skip = "https://github.com/dotnet/roslyn/issues/70376")] public async Task GoToDefinitionFromMetadataSecondHop() { await TestServices.SolutionExplorer.AddDllReferenceAsync(ProjectName, typeof(CSharpGoToDefinition).Assembly.Location, HangMitigatingCancellationToken); diff --git a/src/VisualStudio/IntegrationTest/New.IntegrationTests/VisualBasic/BasicGoToDefinition.cs b/src/VisualStudio/IntegrationTest/New.IntegrationTests/VisualBasic/BasicGoToDefinition.cs index d84da6a12ec1b..f0141ae082838 100644 --- a/src/VisualStudio/IntegrationTest/New.IntegrationTests/VisualBasic/BasicGoToDefinition.cs +++ b/src/VisualStudio/IntegrationTest/New.IntegrationTests/VisualBasic/BasicGoToDefinition.cs @@ -47,7 +47,7 @@ Dim gibberish As SomeClass Assert.False(await TestServices.Shell.IsActiveTabProvisionalAsync(HangMitigatingCancellationToken)); } - [IdeFact] + [IdeFact(Skip = "https://github.com/dotnet/roslyn/issues/70376")] public async Task ObjectBrowserNavigation() { var globalOptions = await TestServices.Shell.GetComponentModelServiceAsync(HangMitigatingCancellationToken);