diff --git a/src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenCallTests.cs b/src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenCallTests.cs index b726a51ee9994..beab66dc48185 100644 --- a/src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenCallTests.cs +++ b/src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenCallTests.cs @@ -1293,181 +1293,309 @@ .locals init (int V_0, [Fact] [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] - public void GenericTypeParameterAsReceiver_Call_InterpolationHandler_Class() + public void GenericTypeParameterAsReceiver_Call_Class_Async_01_ThroughArray() { var source = @" using System; -using System.Runtime.CompilerServices; -using System.Text; - +using System.Threading.Tasks; interface IMoveable { - string Name {get;} - void GetName(int x, [InterpolatedStringHandlerArgument("""")] DummyHandler handler); + void GetName(int x); } class Item : IMoveable { public string Name {get; set;} - public void GetName(int x, [InterpolatedStringHandlerArgument("""")] DummyHandler handler) + public void GetName(int x) { Console.WriteLine(""Position GetName for item '{0}'"", Name); } } +class Item2 : Item {} + class Program { - static void Main() + static async Task Main() { - var item1 = new Item {Name = ""1""}; - Call1(item1); + var item1 = new[] {new Item2 {Name = ""1""}}; + await Call1((Item[])item1); - var item2 = new Item {Name = ""2""}; - Call2(item2); + var item2 = new[] {new Item2 {Name = ""2""}}; + await Call2((Item[])item2); } - static void Call1(T item) where T : class, IMoveable + static async Task Call1(T[] item) where T : class, IMoveable { - item.GetName(GetOffset(ref item), $""log:{0}""); + item[GetArrayIndex()].GetName(await GetOffsetAsync(GetOffset(ref item))); } - static void Call2(T item) where T : IMoveable + static async Task Call2(T[] item) where T : IMoveable { - item.GetName(GetOffset(ref item), $""log""); + item[GetArrayIndex()].GetName(await GetOffsetAsync(GetOffset(ref item))); } static int value = 0; - static int GetOffset(ref T item) + static int GetOffset(ref T[] item) { - item = (T)(IMoveable)new Item {Name = (--value).ToString()}; + item[0] = (T)(IMoveable)new Item2 {Name = (--value).ToString()}; return 0; } -} -[InterpolatedStringHandler] -internal ref struct DummyHandler -{ - private readonly StringBuilder _builder; - public DummyHandler(int literalLength, int formattedCount, IMoveable logger) +#pragma warning disable CS1998 // This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. + static async Task GetOffsetAsync(int i) { - Console.WriteLine(""Position DummyHandler for item '{0}'"", logger.Name); - _builder = new StringBuilder(); + return i; } - public string GetContent() => _builder.ToString(); - public void AppendLiteral(string s) => _builder.Append(s); - public void AppendFormatted(T t) => _builder.Append(t); + static int GetArrayIndex() => 0; } "; - var verifier = CompileAndVerify( - new[] { source, InterpolatedStringHandlerAttribute, InterpolatedStringHandlerArgumentAttribute }, - options: TestOptions.ReleaseExe, expectedOutput: @" -Position DummyHandler for item '1' + var verifier = CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: @" Position GetName for item '1' -Position DummyHandler for item '2' Position GetName for item '2' ").VerifyDiagnostics(); - verifier.VerifyIL("Program.Call1", + verifier.VerifyIL("Program.d__1.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext", @" { - // Code size 57 (0x39) - .maxstack 6 - .locals init (T V_0, - DummyHandler V_1) + // Code size 205 (0xcd) + .maxstack 3 + .locals init (int V_0, + int V_1, + System.Runtime.CompilerServices.TaskAwaiter V_2, + System.Exception V_3) IL_0000: ldarg.0 - IL_0001: stloc.0 - IL_0002: ldloc.0 - IL_0003: box ""T"" - IL_0008: ldarga.s V_0 - IL_000a: call ""int Program.GetOffset(ref T)"" - IL_000f: ldloca.s V_1 - IL_0011: ldc.i4.4 - IL_0012: ldc.i4.1 - IL_0013: ldloc.0 - IL_0014: box ""T"" - IL_0019: call ""DummyHandler..ctor(int, int, IMoveable)"" - IL_001e: ldloca.s V_1 - IL_0020: ldstr ""log:"" - IL_0025: call ""void DummyHandler.AppendLiteral(string)"" - IL_002a: ldloca.s V_1 - IL_002c: ldc.i4.0 - IL_002d: call ""void DummyHandler.AppendFormatted(int)"" - IL_0032: ldloc.1 - IL_0033: callvirt ""void IMoveable.GetName(int, DummyHandler)"" - IL_0038: ret + IL_0001: ldfld ""int Program.d__1.<>1__state"" + IL_0006: stloc.0 + .try + { + IL_0007: ldloc.0 + IL_0008: brfalse.s IL_005f + IL_000a: ldarg.0 + IL_000b: ldarg.0 + IL_000c: ldfld ""T[] Program.d__1.item"" + IL_0011: call ""int Program.GetArrayIndex()"" + IL_0016: ldelem ""T"" + IL_001b: stfld ""T Program.d__1.<>7__wrap1"" + IL_0020: ldarg.0 + IL_0021: ldflda ""T[] Program.d__1.item"" + IL_0026: call ""int Program.GetOffset(ref T[])"" + IL_002b: call ""System.Threading.Tasks.Task Program.GetOffsetAsync(int)"" + IL_0030: callvirt ""System.Runtime.CompilerServices.TaskAwaiter System.Threading.Tasks.Task.GetAwaiter()"" + IL_0035: stloc.2 + IL_0036: ldloca.s V_2 + IL_0038: call ""bool System.Runtime.CompilerServices.TaskAwaiter.IsCompleted.get"" + IL_003d: brtrue.s IL_007b + IL_003f: ldarg.0 + IL_0040: ldc.i4.0 + IL_0041: dup + IL_0042: stloc.0 + IL_0043: stfld ""int Program.d__1.<>1__state"" + IL_0048: ldarg.0 + IL_0049: ldloc.2 + IL_004a: stfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_004f: ldarg.0 + IL_0050: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_0055: ldloca.s V_2 + IL_0057: ldarg.0 + IL_0058: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.AwaitUnsafeOnCompleted, Program.d__1>(ref System.Runtime.CompilerServices.TaskAwaiter, ref Program.d__1)"" + IL_005d: leave.s IL_00cc + IL_005f: ldarg.0 + IL_0060: ldfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_0065: stloc.2 + IL_0066: ldarg.0 + IL_0067: ldflda ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_006c: initobj ""System.Runtime.CompilerServices.TaskAwaiter"" + IL_0072: ldarg.0 + IL_0073: ldc.i4.m1 + IL_0074: dup + IL_0075: stloc.0 + IL_0076: stfld ""int Program.d__1.<>1__state"" + IL_007b: ldloca.s V_2 + IL_007d: call ""int System.Runtime.CompilerServices.TaskAwaiter.GetResult()"" + IL_0082: stloc.1 + IL_0083: ldarg.0 + IL_0084: ldfld ""T Program.d__1.<>7__wrap1"" + IL_0089: box ""T"" + IL_008e: ldloc.1 + IL_008f: callvirt ""void IMoveable.GetName(int)"" + IL_0094: ldarg.0 + IL_0095: ldflda ""T Program.d__1.<>7__wrap1"" + IL_009a: initobj ""T"" + IL_00a0: leave.s IL_00b9 + } + catch System.Exception + { + IL_00a2: stloc.3 + IL_00a3: ldarg.0 + IL_00a4: ldc.i4.s -2 + IL_00a6: stfld ""int Program.d__1.<>1__state"" + IL_00ab: ldarg.0 + IL_00ac: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_00b1: ldloc.3 + IL_00b2: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException(System.Exception)"" + IL_00b7: leave.s IL_00cc + } + IL_00b9: ldarg.0 + IL_00ba: ldc.i4.s -2 + IL_00bc: stfld ""int Program.d__1.<>1__state"" + IL_00c1: ldarg.0 + IL_00c2: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_00c7: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()"" + IL_00cc: ret } "); - verifier.VerifyIL("Program.Call2", + verifier.VerifyIL("Program.d__2.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext", @" { - // Code size 86 (0x56) - .maxstack 6 - .locals init (T& V_0, - T V_1, - T& V_2, - T V_3, - DummyHandler V_4) - IL_0000: ldarga.s V_0 - IL_0002: stloc.2 - IL_0003: ldloca.s V_3 - IL_0005: initobj ""T"" - IL_000b: ldloc.3 - IL_000c: box ""T"" - IL_0011: brtrue.s IL_001e - IL_0013: ldloc.2 - IL_0014: ldobj ""T"" - IL_0019: stloc.1 - IL_001a: ldloca.s V_1 - IL_001c: br.s IL_001f - IL_001e: ldloc.2 - IL_001f: stloc.0 - IL_0020: ldloc.0 - IL_0021: ldarga.s V_0 - IL_0023: call ""int Program.GetOffset(ref T)"" - IL_0028: ldloca.s V_4 - IL_002a: ldc.i4.3 - IL_002b: ldc.i4.0 - IL_002c: ldloc.0 - IL_002d: ldobj ""T"" - IL_0032: box ""T"" - IL_0037: call ""DummyHandler..ctor(int, int, IMoveable)"" - IL_003c: ldloca.s V_4 - IL_003e: ldstr ""log"" - IL_0043: call ""void DummyHandler.AppendLiteral(string)"" - IL_0048: ldloc.s V_4 - IL_004a: constrained. ""T"" - IL_0050: callvirt ""void IMoveable.GetName(int, DummyHandler)"" - IL_0055: ret + // Code size 318 (0x13e) + .maxstack 3 + .locals init (int V_0, + int V_1, + T V_2, + System.Runtime.CompilerServices.TaskAwaiter V_3, + System.Exception V_4) + IL_0000: ldarg.0 + IL_0001: ldfld ""int Program.d__2.<>1__state"" + IL_0006: stloc.0 + .try + { + IL_0007: ldloc.0 + IL_0008: brfalse IL_00a1 + IL_000d: ldarg.0 + IL_000e: ldarg.0 + IL_000f: ldfld ""T[] Program.d__2.item"" + IL_0014: stfld ""T[] Program.d__2.<>7__wrap2"" + IL_0019: ldarg.0 + IL_001a: call ""int Program.GetArrayIndex()"" + IL_001f: stfld ""int Program.d__2.<>7__wrap3"" + IL_0024: ldarg.0 + IL_0025: ldfld ""T[] Program.d__2.<>7__wrap2"" + IL_002a: ldarg.0 + IL_002b: ldfld ""int Program.d__2.<>7__wrap3"" + IL_0030: readonly. + IL_0032: ldelema ""T"" + IL_0037: pop + IL_0038: ldloca.s V_2 + IL_003a: initobj ""T"" + IL_0040: ldloc.2 + IL_0041: box ""T"" + IL_0046: brtrue.s IL_005f + IL_0048: ldarg.0 + IL_0049: ldarg.0 + IL_004a: ldfld ""T[] Program.d__2.<>7__wrap2"" + IL_004f: ldarg.0 + IL_0050: ldfld ""int Program.d__2.<>7__wrap3"" + IL_0055: ldelem ""T"" + IL_005a: stfld ""T Program.d__2.<>7__wrap1"" + IL_005f: ldarg.0 + IL_0060: ldflda ""T[] Program.d__2.item"" + IL_0065: call ""int Program.GetOffset(ref T[])"" + IL_006a: call ""System.Threading.Tasks.Task Program.GetOffsetAsync(int)"" + IL_006f: callvirt ""System.Runtime.CompilerServices.TaskAwaiter System.Threading.Tasks.Task.GetAwaiter()"" + IL_0074: stloc.3 + IL_0075: ldloca.s V_3 + IL_0077: call ""bool System.Runtime.CompilerServices.TaskAwaiter.IsCompleted.get"" + IL_007c: brtrue.s IL_00bd + IL_007e: ldarg.0 + IL_007f: ldc.i4.0 + IL_0080: dup + IL_0081: stloc.0 + IL_0082: stfld ""int Program.d__2.<>1__state"" + IL_0087: ldarg.0 + IL_0088: ldloc.3 + IL_0089: stfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__2.<>u__1"" + IL_008e: ldarg.0 + IL_008f: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__2.<>t__builder"" + IL_0094: ldloca.s V_3 + IL_0096: ldarg.0 + IL_0097: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.AwaitUnsafeOnCompleted, Program.d__2>(ref System.Runtime.CompilerServices.TaskAwaiter, ref Program.d__2)"" + IL_009c: leave IL_013d + IL_00a1: ldarg.0 + IL_00a2: ldfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__2.<>u__1"" + IL_00a7: stloc.3 + IL_00a8: ldarg.0 + IL_00a9: ldflda ""System.Runtime.CompilerServices.TaskAwaiter Program.d__2.<>u__1"" + IL_00ae: initobj ""System.Runtime.CompilerServices.TaskAwaiter"" + IL_00b4: ldarg.0 + IL_00b5: ldc.i4.m1 + IL_00b6: dup + IL_00b7: stloc.0 + IL_00b8: stfld ""int Program.d__2.<>1__state"" + IL_00bd: ldloca.s V_3 + IL_00bf: call ""int System.Runtime.CompilerServices.TaskAwaiter.GetResult()"" + IL_00c4: stloc.1 + IL_00c5: ldloca.s V_2 + IL_00c7: initobj ""T"" + IL_00cd: ldloc.2 + IL_00ce: box ""T"" + IL_00d3: brtrue.s IL_00dd + IL_00d5: ldarg.0 + IL_00d6: ldflda ""T Program.d__2.<>7__wrap1"" + IL_00db: br.s IL_00f0 + IL_00dd: ldarg.0 + IL_00de: ldfld ""T[] Program.d__2.<>7__wrap2"" + IL_00e3: ldarg.0 + IL_00e4: ldfld ""int Program.d__2.<>7__wrap3"" + IL_00e9: readonly. + IL_00eb: ldelema ""T"" + IL_00f0: ldloc.1 + IL_00f1: constrained. ""T"" + IL_00f7: callvirt ""void IMoveable.GetName(int)"" + IL_00fc: ldarg.0 + IL_00fd: ldnull + IL_00fe: stfld ""T[] Program.d__2.<>7__wrap2"" + IL_0103: ldarg.0 + IL_0104: ldflda ""T Program.d__2.<>7__wrap1"" + IL_0109: initobj ""T"" + IL_010f: leave.s IL_012a + } + catch System.Exception + { + IL_0111: stloc.s V_4 + IL_0113: ldarg.0 + IL_0114: ldc.i4.s -2 + IL_0116: stfld ""int Program.d__2.<>1__state"" + IL_011b: ldarg.0 + IL_011c: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__2.<>t__builder"" + IL_0121: ldloc.s V_4 + IL_0123: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException(System.Exception)"" + IL_0128: leave.s IL_013d + } + IL_012a: ldarg.0 + IL_012b: ldc.i4.s -2 + IL_012d: stfld ""int Program.d__2.<>1__state"" + IL_0132: ldarg.0 + IL_0133: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__2.<>t__builder"" + IL_0138: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()"" + IL_013d: ret } "); } [Fact] [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] - public void GenericTypeParameterAsReceiver_Call_InterpolationHandler_Struct() + public void GenericTypeParameterAsReceiver_Call_Struct_Async_01_ThroughArray() { var source = @" using System; -using System.Runtime.CompilerServices; -using System.Text; - +using System.Threading.Tasks; interface IMoveable { - string Name {get;} - void GetName(int x, [InterpolatedStringHandlerArgument("""")] DummyHandler handler); + void GetName(int x); } struct Item : IMoveable { public string Name {get; set;} - public void GetName(int x, [InterpolatedStringHandlerArgument("""")] DummyHandler handler) + public void GetName(int x) { Console.WriteLine(""Position GetName for item '{0}'"", Name); } @@ -1475,94 +1603,154 @@ public void GetName(int x, [InterpolatedStringHandlerArgument("""")] DummyHandle class Program { - static void Main() + static async Task Main() { - var item1 = new Item {Name = ""1""}; - Call1(item1); + var item1 = new[] {new Item {Name = ""1""}}; + await Call1(item1); - var item2 = new Item {Name = ""2""}; - Call2(item2); + var item2 = new[] {new Item {Name = ""2""}}; + await Call2(item2); } - static void Call1(T item) where T : struct, IMoveable + static async Task Call1(T[] item) where T : struct, IMoveable { - item.GetName(GetOffset(ref item), $""log:{0}""); + item[GetArrayIndex()].GetName(await GetOffsetAsync(GetOffset(ref item))); } - static void Call2(T item) where T : IMoveable + static async Task Call2(T[] item) where T : IMoveable { - item.GetName(GetOffset(ref item), $""log""); + item[GetArrayIndex()].GetName(await GetOffsetAsync(GetOffset(ref item))); } static int value = 0; - static int GetOffset(ref T item) + static int GetOffset(ref T[] item) { - item = (T)(IMoveable)new Item {Name = (--value).ToString()}; + item[0] = (T)(IMoveable)new Item {Name = (--value).ToString()}; return 0; } -} -[InterpolatedStringHandler] -internal ref struct DummyHandler -{ - private readonly StringBuilder _builder; - public DummyHandler(int literalLength, int formattedCount, IMoveable logger) +#pragma warning disable CS1998 // This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. + static async Task GetOffsetAsync(int i) { - Console.WriteLine(""Position DummyHandler for item '{0}'"", logger.Name); - _builder = new StringBuilder(); + return i; } - public string GetContent() => _builder.ToString(); - public void AppendLiteral(string s) => _builder.Append(s); - public void AppendFormatted(T t) => _builder.Append(t); + static int GetArrayIndex() => 0; } "; - var verifier = CompileAndVerify( - new[] { source, InterpolatedStringHandlerAttribute, InterpolatedStringHandlerArgumentAttribute }, - options: TestOptions.ReleaseExe, expectedOutput: @" -Position DummyHandler for item '-1' + var verifier = CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: @" Position GetName for item '-1' -Position DummyHandler for item '-2' Position GetName for item '-2' ").VerifyDiagnostics(); - verifier.VerifyIL("Program.Call1", + verifier.VerifyIL("Program.d__1.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext", @" { - // Code size 64 (0x40) - .maxstack 6 - .locals init (T& V_0, - DummyHandler V_1) - IL_0000: ldarga.s V_0 - IL_0002: stloc.0 - IL_0003: ldloc.0 - IL_0004: ldarga.s V_0 - IL_0006: call ""int Program.GetOffset(ref T)"" - IL_000b: ldloca.s V_1 - IL_000d: ldc.i4.4 - IL_000e: ldc.i4.1 - IL_000f: ldloc.0 - IL_0010: ldobj ""T"" - IL_0015: box ""T"" - IL_001a: call ""DummyHandler..ctor(int, int, IMoveable)"" - IL_001f: ldloca.s V_1 - IL_0021: ldstr ""log:"" - IL_0026: call ""void DummyHandler.AppendLiteral(string)"" - IL_002b: ldloca.s V_1 - IL_002d: ldc.i4.0 - IL_002e: call ""void DummyHandler.AppendFormatted(int)"" - IL_0033: ldloc.1 - IL_0034: constrained. ""T"" - IL_003a: callvirt ""void IMoveable.GetName(int, DummyHandler)"" - IL_003f: ret + // Code size 235 (0xeb) + .maxstack 3 + .locals init (int V_0, + int V_1, + System.Runtime.CompilerServices.TaskAwaiter V_2, + System.Exception V_3) + IL_0000: ldarg.0 + IL_0001: ldfld ""int Program.d__1.<>1__state"" + IL_0006: stloc.0 + .try + { + IL_0007: ldloc.0 + IL_0008: brfalse.s IL_0074 + IL_000a: ldarg.0 + IL_000b: ldarg.0 + IL_000c: ldfld ""T[] Program.d__1.item"" + IL_0011: stfld ""T[] Program.d__1.<>7__wrap1"" + IL_0016: ldarg.0 + IL_0017: call ""int Program.GetArrayIndex()"" + IL_001c: stfld ""int Program.d__1.<>7__wrap2"" + IL_0021: ldarg.0 + IL_0022: ldfld ""T[] Program.d__1.<>7__wrap1"" + IL_0027: ldarg.0 + IL_0028: ldfld ""int Program.d__1.<>7__wrap2"" + IL_002d: readonly. + IL_002f: ldelema ""T"" + IL_0034: pop + IL_0035: ldarg.0 + IL_0036: ldflda ""T[] Program.d__1.item"" + IL_003b: call ""int Program.GetOffset(ref T[])"" + IL_0040: call ""System.Threading.Tasks.Task Program.GetOffsetAsync(int)"" + IL_0045: callvirt ""System.Runtime.CompilerServices.TaskAwaiter System.Threading.Tasks.Task.GetAwaiter()"" + IL_004a: stloc.2 + IL_004b: ldloca.s V_2 + IL_004d: call ""bool System.Runtime.CompilerServices.TaskAwaiter.IsCompleted.get"" + IL_0052: brtrue.s IL_0090 + IL_0054: ldarg.0 + IL_0055: ldc.i4.0 + IL_0056: dup + IL_0057: stloc.0 + IL_0058: stfld ""int Program.d__1.<>1__state"" + IL_005d: ldarg.0 + IL_005e: ldloc.2 + IL_005f: stfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_0064: ldarg.0 + IL_0065: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_006a: ldloca.s V_2 + IL_006c: ldarg.0 + IL_006d: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.AwaitUnsafeOnCompleted, Program.d__1>(ref System.Runtime.CompilerServices.TaskAwaiter, ref Program.d__1)"" + IL_0072: leave.s IL_00ea + IL_0074: ldarg.0 + IL_0075: ldfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_007a: stloc.2 + IL_007b: ldarg.0 + IL_007c: ldflda ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_0081: initobj ""System.Runtime.CompilerServices.TaskAwaiter"" + IL_0087: ldarg.0 + IL_0088: ldc.i4.m1 + IL_0089: dup + IL_008a: stloc.0 + IL_008b: stfld ""int Program.d__1.<>1__state"" + IL_0090: ldloca.s V_2 + IL_0092: call ""int System.Runtime.CompilerServices.TaskAwaiter.GetResult()"" + IL_0097: stloc.1 + IL_0098: ldarg.0 + IL_0099: ldfld ""T[] Program.d__1.<>7__wrap1"" + IL_009e: ldarg.0 + IL_009f: ldfld ""int Program.d__1.<>7__wrap2"" + IL_00a4: readonly. + IL_00a6: ldelema ""T"" + IL_00ab: ldloc.1 + IL_00ac: constrained. ""T"" + IL_00b2: callvirt ""void IMoveable.GetName(int)"" + IL_00b7: ldarg.0 + IL_00b8: ldnull + IL_00b9: stfld ""T[] Program.d__1.<>7__wrap1"" + IL_00be: leave.s IL_00d7 + } + catch System.Exception + { + IL_00c0: stloc.3 + IL_00c1: ldarg.0 + IL_00c2: ldc.i4.s -2 + IL_00c4: stfld ""int Program.d__1.<>1__state"" + IL_00c9: ldarg.0 + IL_00ca: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_00cf: ldloc.3 + IL_00d0: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException(System.Exception)"" + IL_00d5: leave.s IL_00ea + } + IL_00d7: ldarg.0 + IL_00d8: ldc.i4.s -2 + IL_00da: stfld ""int Program.d__1.<>1__state"" + IL_00df: ldarg.0 + IL_00e0: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_00e5: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()"" + IL_00ea: ret } "); } [Fact] [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] - public void GenericTypeParameterAsReceiver_Call_InterpolationHandler_Class_Ref() + public void GenericTypeParameterAsReceiver_Call_InterpolationHandler_Class() { var source = @" using System; @@ -1591,18 +1779,18 @@ class Program static void Main() { var item1 = new Item {Name = ""1""}; - Call1(ref item1); + Call1(item1); var item2 = new Item {Name = ""2""}; - Call2(ref item2); + Call2(item2); } - static void Call1(ref T item) where T : class, IMoveable + static void Call1(T item) where T : class, IMoveable { item.GetName(GetOffset(ref item), $""log:{0}""); } - static void Call2(ref T item) where T : IMoveable + static void Call2(T item) where T : IMoveable { item.GetName(GetOffset(ref item), $""log""); } @@ -1643,87 +1831,82 @@ public DummyHandler(int literalLength, int formattedCount, IMoveable logger) verifier.VerifyIL("Program.Call1", @" { - // Code size 70 (0x46) + // Code size 57 (0x39) .maxstack 6 - .locals init (T& V_0, - T V_1, - DummyHandler V_2) + .locals init (T V_0, + DummyHandler V_1) IL_0000: ldarg.0 - IL_0001: ldobj ""T"" - IL_0006: stloc.1 - IL_0007: ldloca.s V_1 - IL_0009: stloc.0 - IL_000a: ldloc.0 - IL_000b: ldarg.0 - IL_000c: call ""int Program.GetOffset(ref T)"" - IL_0011: ldloca.s V_2 - IL_0013: ldc.i4.4 - IL_0014: ldc.i4.1 - IL_0015: ldloc.0 - IL_0016: ldobj ""T"" - IL_001b: box ""T"" - IL_0020: call ""DummyHandler..ctor(int, int, IMoveable)"" - IL_0025: ldloca.s V_2 - IL_0027: ldstr ""log:"" - IL_002c: call ""void DummyHandler.AppendLiteral(string)"" - IL_0031: ldloca.s V_2 - IL_0033: ldc.i4.0 - IL_0034: call ""void DummyHandler.AppendFormatted(int)"" - IL_0039: ldloc.2 - IL_003a: constrained. ""T"" - IL_0040: callvirt ""void IMoveable.GetName(int, DummyHandler)"" - IL_0045: ret + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: box ""T"" + IL_0008: ldarga.s V_0 + IL_000a: call ""int Program.GetOffset(ref T)"" + IL_000f: ldloca.s V_1 + IL_0011: ldc.i4.4 + IL_0012: ldc.i4.1 + IL_0013: ldloc.0 + IL_0014: box ""T"" + IL_0019: call ""DummyHandler..ctor(int, int, IMoveable)"" + IL_001e: ldloca.s V_1 + IL_0020: ldstr ""log:"" + IL_0025: call ""void DummyHandler.AppendLiteral(string)"" + IL_002a: ldloca.s V_1 + IL_002c: ldc.i4.0 + IL_002d: call ""void DummyHandler.AppendFormatted(int)"" + IL_0032: ldloc.1 + IL_0033: callvirt ""void IMoveable.GetName(int, DummyHandler)"" + IL_0038: ret } "); verifier.VerifyIL("Program.Call2", @" { - // Code size 84 (0x54) + // Code size 86 (0x56) .maxstack 6 .locals init (T& V_0, T V_1, T& V_2, T V_3, DummyHandler V_4) - IL_0000: ldarg.0 - IL_0001: stloc.2 - IL_0002: ldloca.s V_3 - IL_0004: initobj ""T"" - IL_000a: ldloc.3 - IL_000b: box ""T"" - IL_0010: brtrue.s IL_001d - IL_0012: ldloc.2 - IL_0013: ldobj ""T"" - IL_0018: stloc.1 - IL_0019: ldloca.s V_1 - IL_001b: br.s IL_001e - IL_001d: ldloc.2 - IL_001e: stloc.0 - IL_001f: ldloc.0 - IL_0020: ldarg.0 - IL_0021: call ""int Program.GetOffset(ref T)"" - IL_0026: ldloca.s V_4 - IL_0028: ldc.i4.3 - IL_0029: ldc.i4.0 - IL_002a: ldloc.0 - IL_002b: ldobj ""T"" - IL_0030: box ""T"" - IL_0035: call ""DummyHandler..ctor(int, int, IMoveable)"" - IL_003a: ldloca.s V_4 - IL_003c: ldstr ""log"" - IL_0041: call ""void DummyHandler.AppendLiteral(string)"" - IL_0046: ldloc.s V_4 - IL_0048: constrained. ""T"" - IL_004e: callvirt ""void IMoveable.GetName(int, DummyHandler)"" - IL_0053: ret + IL_0000: ldarga.s V_0 + IL_0002: stloc.2 + IL_0003: ldloca.s V_3 + IL_0005: initobj ""T"" + IL_000b: ldloc.3 + IL_000c: box ""T"" + IL_0011: brtrue.s IL_001e + IL_0013: ldloc.2 + IL_0014: ldobj ""T"" + IL_0019: stloc.1 + IL_001a: ldloca.s V_1 + IL_001c: br.s IL_001f + IL_001e: ldloc.2 + IL_001f: stloc.0 + IL_0020: ldloc.0 + IL_0021: ldarga.s V_0 + IL_0023: call ""int Program.GetOffset(ref T)"" + IL_0028: ldloca.s V_4 + IL_002a: ldc.i4.3 + IL_002b: ldc.i4.0 + IL_002c: ldloc.0 + IL_002d: ldobj ""T"" + IL_0032: box ""T"" + IL_0037: call ""DummyHandler..ctor(int, int, IMoveable)"" + IL_003c: ldloca.s V_4 + IL_003e: ldstr ""log"" + IL_0043: call ""void DummyHandler.AppendLiteral(string)"" + IL_0048: ldloc.s V_4 + IL_004a: constrained. ""T"" + IL_0050: callvirt ""void IMoveable.GetName(int, DummyHandler)"" + IL_0055: ret } "); } [Fact] [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] - public void GenericTypeParameterAsReceiver_Call_InterpolationHandler_Struct_Ref() + public void GenericTypeParameterAsReceiver_Call_InterpolationHandler_Struct() { var source = @" using System; @@ -1752,18 +1935,18 @@ class Program static void Main() { var item1 = new Item {Name = ""1""}; - Call1(ref item1); + Call1(item1); var item2 = new Item {Name = ""2""}; - Call2(ref item2); + Call2(item2); } - static void Call1(ref T item) where T : struct, IMoveable + static void Call1(T item) where T : struct, IMoveable { item.GetName(GetOffset(ref item), $""log:{0}""); } - static void Call2(ref T item) where T : IMoveable + static void Call2(T item) where T : IMoveable { item.GetName(GetOffset(ref item), $""log""); } @@ -1804,53 +1987,57 @@ public DummyHandler(int literalLength, int formattedCount, IMoveable logger) verifier.VerifyIL("Program.Call1", @" { - // Code size 62 (0x3e) + // Code size 64 (0x40) .maxstack 6 .locals init (T& V_0, DummyHandler V_1) - IL_0000: ldarg.0 - IL_0001: stloc.0 - IL_0002: ldloc.0 - IL_0003: ldarg.0 - IL_0004: call ""int Program.GetOffset(ref T)"" - IL_0009: ldloca.s V_1 - IL_000b: ldc.i4.4 - IL_000c: ldc.i4.1 - IL_000d: ldloc.0 - IL_000e: ldobj ""T"" - IL_0013: box ""T"" - IL_0018: call ""DummyHandler..ctor(int, int, IMoveable)"" - IL_001d: ldloca.s V_1 - IL_001f: ldstr ""log:"" - IL_0024: call ""void DummyHandler.AppendLiteral(string)"" - IL_0029: ldloca.s V_1 - IL_002b: ldc.i4.0 - IL_002c: call ""void DummyHandler.AppendFormatted(int)"" - IL_0031: ldloc.1 - IL_0032: constrained. ""T"" - IL_0038: callvirt ""void IMoveable.GetName(int, DummyHandler)"" - IL_003d: ret -} -"); - } - - [Fact] - [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] - public void GenericTypeParameterAsReceiver_Call_Conditional_Class() - { + IL_0000: ldarga.s V_0 + IL_0002: stloc.0 + IL_0003: ldloc.0 + IL_0004: ldarga.s V_0 + IL_0006: call ""int Program.GetOffset(ref T)"" + IL_000b: ldloca.s V_1 + IL_000d: ldc.i4.4 + IL_000e: ldc.i4.1 + IL_000f: ldloc.0 + IL_0010: ldobj ""T"" + IL_0015: box ""T"" + IL_001a: call ""DummyHandler..ctor(int, int, IMoveable)"" + IL_001f: ldloca.s V_1 + IL_0021: ldstr ""log:"" + IL_0026: call ""void DummyHandler.AppendLiteral(string)"" + IL_002b: ldloca.s V_1 + IL_002d: ldc.i4.0 + IL_002e: call ""void DummyHandler.AppendFormatted(int)"" + IL_0033: ldloc.1 + IL_0034: constrained. ""T"" + IL_003a: callvirt ""void IMoveable.GetName(int, DummyHandler)"" + IL_003f: ret +} +"); + } + + [Fact] + [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] + public void GenericTypeParameterAsReceiver_Call_InterpolationHandler_Class_Ref() + { var source = @" using System; +using System.Runtime.CompilerServices; +using System.Text; + interface IMoveable { - void GetName(int x); + string Name {get;} + void GetName(int x, [InterpolatedStringHandlerArgument("""")] DummyHandler handler); } class Item : IMoveable { public string Name {get; set;} - public void GetName(int x) + public void GetName(int x, [InterpolatedStringHandlerArgument("""")] DummyHandler handler) { Console.WriteLine(""Position GetName for item '{0}'"", Name); } @@ -1861,20 +2048,20 @@ class Program static void Main() { var item1 = new Item {Name = ""1""}; - Call1(item1); + Call1(ref item1); var item2 = new Item {Name = ""2""}; - Call2(item2); + Call2(ref item2); } - static void Call1(T item) where T : class, IMoveable + static void Call1(ref T item) where T : class, IMoveable { - item?.GetName(GetOffset(ref item)); + item.GetName(GetOffset(ref item), $""log:{0}""); } - static void Call2(T item) where T : IMoveable + static void Call2(ref T item) where T : IMoveable { - item?.GetName(GetOffset(ref item)); + item.GetName(GetOffset(ref item), $""log""); } static int value = 0; @@ -1884,77 +2071,134 @@ static int GetOffset(ref T item) return 0; } } + +[InterpolatedStringHandler] +internal ref struct DummyHandler +{ + private readonly StringBuilder _builder; + public DummyHandler(int literalLength, int formattedCount, IMoveable logger) + { + Console.WriteLine(""Position DummyHandler for item '{0}'"", logger.Name); + _builder = new StringBuilder(); + } + public string GetContent() => _builder.ToString(); + + public void AppendLiteral(string s) => _builder.Append(s); + public void AppendFormatted(T t) => _builder.Append(t); +} "; - var verifier = CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: @" + var verifier = CompileAndVerify( + new[] { source, InterpolatedStringHandlerAttribute, InterpolatedStringHandlerArgumentAttribute }, + options: TestOptions.ReleaseExe, expectedOutput: @" +Position DummyHandler for item '1' Position GetName for item '1' +Position DummyHandler for item '2' Position GetName for item '2' ").VerifyDiagnostics(); verifier.VerifyIL("Program.Call1", @" { - // Code size 24 (0x18) - .maxstack 2 + // Code size 70 (0x46) + .maxstack 6 + .locals init (T& V_0, + T V_1, + DummyHandler V_2) IL_0000: ldarg.0 - IL_0001: box ""T"" - IL_0006: dup - IL_0007: brtrue.s IL_000b - IL_0009: pop - IL_000a: ret - IL_000b: ldarga.s V_0 - IL_000d: call ""int Program.GetOffset(ref T)"" - IL_0012: callvirt ""void IMoveable.GetName(int)"" - IL_0017: ret + IL_0001: ldobj ""T"" + IL_0006: stloc.1 + IL_0007: ldloca.s V_1 + IL_0009: stloc.0 + IL_000a: ldloc.0 + IL_000b: ldarg.0 + IL_000c: call ""int Program.GetOffset(ref T)"" + IL_0011: ldloca.s V_2 + IL_0013: ldc.i4.4 + IL_0014: ldc.i4.1 + IL_0015: ldloc.0 + IL_0016: ldobj ""T"" + IL_001b: box ""T"" + IL_0020: call ""DummyHandler..ctor(int, int, IMoveable)"" + IL_0025: ldloca.s V_2 + IL_0027: ldstr ""log:"" + IL_002c: call ""void DummyHandler.AppendLiteral(string)"" + IL_0031: ldloca.s V_2 + IL_0033: ldc.i4.0 + IL_0034: call ""void DummyHandler.AppendFormatted(int)"" + IL_0039: ldloc.2 + IL_003a: constrained. ""T"" + IL_0040: callvirt ""void IMoveable.GetName(int, DummyHandler)"" + IL_0045: ret } "); verifier.VerifyIL("Program.Call2", @" { - // Code size 55 (0x37) - .maxstack 2 - .locals init (T V_0) - IL_0000: ldarga.s V_0 - IL_0002: ldloca.s V_0 + // Code size 84 (0x54) + .maxstack 6 + .locals init (T& V_0, + T V_1, + T& V_2, + T V_3, + DummyHandler V_4) + IL_0000: ldarg.0 + IL_0001: stloc.2 + IL_0002: ldloca.s V_3 IL_0004: initobj ""T"" - IL_000a: ldloc.0 + IL_000a: ldloc.3 IL_000b: box ""T"" - IL_0010: brtrue.s IL_0024 - IL_0012: ldobj ""T"" - IL_0017: stloc.0 - IL_0018: ldloca.s V_0 - IL_001a: ldloc.0 - IL_001b: box ""T"" - IL_0020: brtrue.s IL_0024 - IL_0022: pop - IL_0023: ret - IL_0024: ldarga.s V_0 - IL_0026: call ""int Program.GetOffset(ref T)"" - IL_002b: constrained. ""T"" - IL_0031: callvirt ""void IMoveable.GetName(int)"" - IL_0036: ret + IL_0010: brtrue.s IL_001d + IL_0012: ldloc.2 + IL_0013: ldobj ""T"" + IL_0018: stloc.1 + IL_0019: ldloca.s V_1 + IL_001b: br.s IL_001e + IL_001d: ldloc.2 + IL_001e: stloc.0 + IL_001f: ldloc.0 + IL_0020: ldarg.0 + IL_0021: call ""int Program.GetOffset(ref T)"" + IL_0026: ldloca.s V_4 + IL_0028: ldc.i4.3 + IL_0029: ldc.i4.0 + IL_002a: ldloc.0 + IL_002b: ldobj ""T"" + IL_0030: box ""T"" + IL_0035: call ""DummyHandler..ctor(int, int, IMoveable)"" + IL_003a: ldloca.s V_4 + IL_003c: ldstr ""log"" + IL_0041: call ""void DummyHandler.AppendLiteral(string)"" + IL_0046: ldloc.s V_4 + IL_0048: constrained. ""T"" + IL_004e: callvirt ""void IMoveable.GetName(int, DummyHandler)"" + IL_0053: ret } "); } [Fact] [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] - public void GenericTypeParameterAsReceiver_Call_Conditional_Struct() + public void GenericTypeParameterAsReceiver_Call_InterpolationHandler_Struct_Ref() { var source = @" using System; +using System.Runtime.CompilerServices; +using System.Text; + interface IMoveable { - void GetName(int x); + string Name {get;} + void GetName(int x, [InterpolatedStringHandlerArgument("""")] DummyHandler handler); } struct Item : IMoveable { public string Name {get; set;} - public void GetName(int x) + public void GetName(int x, [InterpolatedStringHandlerArgument("""")] DummyHandler handler) { Console.WriteLine(""Position GetName for item '{0}'"", Name); } @@ -1964,13 +2208,21 @@ class Program { static void Main() { + var item1 = new Item {Name = ""1""}; + Call1(ref item1); + var item2 = new Item {Name = ""2""}; - Call2(item2); + Call2(ref item2); } - static void Call2(T item) where T : IMoveable + static void Call1(ref T item) where T : struct, IMoveable { - item?.GetName(GetOffset(ref item)); + item.GetName(GetOffset(ref item), $""log:{0}""); + } + + static void Call2(ref T item) where T : IMoveable + { + item.GetName(GetOffset(ref item), $""log""); } static int value = 0; @@ -1980,16 +2232,68 @@ static int GetOffset(ref T item) return 0; } } + +[InterpolatedStringHandler] +internal ref struct DummyHandler +{ + private readonly StringBuilder _builder; + public DummyHandler(int literalLength, int formattedCount, IMoveable logger) + { + Console.WriteLine(""Position DummyHandler for item '{0}'"", logger.Name); + _builder = new StringBuilder(); + } + public string GetContent() => _builder.ToString(); + + public void AppendLiteral(string s) => _builder.Append(s); + public void AppendFormatted(T t) => _builder.Append(t); +} "; - CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: @" + var verifier = CompileAndVerify( + new[] { source, InterpolatedStringHandlerAttribute, InterpolatedStringHandlerArgumentAttribute }, + options: TestOptions.ReleaseExe, expectedOutput: @" +Position DummyHandler for item '-1' Position GetName for item '-1' +Position DummyHandler for item '-2' +Position GetName for item '-2' ").VerifyDiagnostics(); + + verifier.VerifyIL("Program.Call1", +@" +{ + // Code size 62 (0x3e) + .maxstack 6 + .locals init (T& V_0, + DummyHandler V_1) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldarg.0 + IL_0004: call ""int Program.GetOffset(ref T)"" + IL_0009: ldloca.s V_1 + IL_000b: ldc.i4.4 + IL_000c: ldc.i4.1 + IL_000d: ldloc.0 + IL_000e: ldobj ""T"" + IL_0013: box ""T"" + IL_0018: call ""DummyHandler..ctor(int, int, IMoveable)"" + IL_001d: ldloca.s V_1 + IL_001f: ldstr ""log:"" + IL_0024: call ""void DummyHandler.AppendLiteral(string)"" + IL_0029: ldloca.s V_1 + IL_002b: ldc.i4.0 + IL_002c: call ""void DummyHandler.AppendFormatted(int)"" + IL_0031: ldloc.1 + IL_0032: constrained. ""T"" + IL_0038: callvirt ""void IMoveable.GetName(int, DummyHandler)"" + IL_003d: ret +} +"); } [Fact] [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] - public void GenericTypeParameterAsReceiver_Call_Conditional_Class_Ref() + public void GenericTypeParameterAsReceiver_Call_Conditional_Class() { var source = @" using System; @@ -2014,18 +2318,18 @@ class Program static void Main() { var item1 = new Item {Name = ""1""}; - Call1(ref item1); + Call1(item1); var item2 = new Item {Name = ""2""}; - Call2(ref item2); + Call2(item2); } - static void Call1(ref T item) where T : class, IMoveable + static void Call1(T item) where T : class, IMoveable { item?.GetName(GetOffset(ref item)); } - static void Call2(ref T item) where T : IMoveable + static void Call2(T item) where T : IMoveable { item?.GetName(GetOffset(ref item)); } @@ -2047,7 +2351,160 @@ static int GetOffset(ref T item) verifier.VerifyIL("Program.Call1", @" { - // Code size 28 (0x1c) + // Code size 24 (0x18) + .maxstack 2 + IL_0000: ldarg.0 + IL_0001: box ""T"" + IL_0006: dup + IL_0007: brtrue.s IL_000b + IL_0009: pop + IL_000a: ret + IL_000b: ldarga.s V_0 + IL_000d: call ""int Program.GetOffset(ref T)"" + IL_0012: callvirt ""void IMoveable.GetName(int)"" + IL_0017: ret +} +"); + + verifier.VerifyIL("Program.Call2", +@" +{ + // Code size 55 (0x37) + .maxstack 2 + .locals init (T V_0) + IL_0000: ldarga.s V_0 + IL_0002: ldloca.s V_0 + IL_0004: initobj ""T"" + IL_000a: ldloc.0 + IL_000b: box ""T"" + IL_0010: brtrue.s IL_0024 + IL_0012: ldobj ""T"" + IL_0017: stloc.0 + IL_0018: ldloca.s V_0 + IL_001a: ldloc.0 + IL_001b: box ""T"" + IL_0020: brtrue.s IL_0024 + IL_0022: pop + IL_0023: ret + IL_0024: ldarga.s V_0 + IL_0026: call ""int Program.GetOffset(ref T)"" + IL_002b: constrained. ""T"" + IL_0031: callvirt ""void IMoveable.GetName(int)"" + IL_0036: ret +} +"); + } + + [Fact] + [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] + public void GenericTypeParameterAsReceiver_Call_Conditional_Struct() + { + var source = @" +using System; + +interface IMoveable +{ + void GetName(int x); +} + +struct Item : IMoveable +{ + public string Name {get; set;} + + public void GetName(int x) + { + Console.WriteLine(""Position GetName for item '{0}'"", Name); + } +} + +class Program +{ + static void Main() + { + var item2 = new Item {Name = ""2""}; + Call2(item2); + } + + static void Call2(T item) where T : IMoveable + { + item?.GetName(GetOffset(ref item)); + } + + static int value = 0; + static int GetOffset(ref T item) + { + item = (T)(IMoveable)new Item {Name = (--value).ToString()}; + return 0; + } +} +"; + + CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: @" +Position GetName for item '-1' +").VerifyDiagnostics(); + } + + [Fact] + [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] + public void GenericTypeParameterAsReceiver_Call_Conditional_Class_Ref() + { + var source = @" +using System; + +interface IMoveable +{ + void GetName(int x); +} + +class Item : IMoveable +{ + public string Name {get; set;} + + public void GetName(int x) + { + Console.WriteLine(""Position GetName for item '{0}'"", Name); + } +} + +class Program +{ + static void Main() + { + var item1 = new Item {Name = ""1""}; + Call1(ref item1); + + var item2 = new Item {Name = ""2""}; + Call2(ref item2); + } + + static void Call1(ref T item) where T : class, IMoveable + { + item?.GetName(GetOffset(ref item)); + } + + static void Call2(ref T item) where T : IMoveable + { + item?.GetName(GetOffset(ref item)); + } + + static int value = 0; + static int GetOffset(ref T item) + { + item = (T)(IMoveable)new Item {Name = (--value).ToString()}; + return 0; + } +} +"; + + var verifier = CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: @" +Position GetName for item '1' +Position GetName for item '2' +").VerifyDiagnostics(); + + verifier.VerifyIL("Program.Call1", +@" +{ + // Code size 28 (0x1c) .maxstack 2 IL_0000: ldarg.0 IL_0001: ldobj ""T"" @@ -8638,34 +9095,1592 @@ .locals init (int V_0, IL_0150: ldarg.0 IL_0151: ldflda ""T Program.d__2.<>7__wrap1"" IL_0156: initobj ""T"" - IL_015c: leave.s IL_0177 + IL_015c: leave.s IL_0177 + } + catch System.Exception + { + IL_015e: stloc.s V_7 + IL_0160: ldarg.0 + IL_0161: ldc.i4.s -2 + IL_0163: stfld ""int Program.d__2.<>1__state"" + IL_0168: ldarg.0 + IL_0169: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__2.<>t__builder"" + IL_016e: ldloc.s V_7 + IL_0170: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException(System.Exception)"" + IL_0175: leave.s IL_018a + } + IL_0177: ldarg.0 + IL_0178: ldc.i4.s -2 + IL_017a: stfld ""int Program.d__2.<>1__state"" + IL_017f: ldarg.0 + IL_0180: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__2.<>t__builder"" + IL_0185: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()"" + IL_018a: ret +} +"); + } + + [Fact] + [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] + public void GenericTypeParameterAsReceiver_Increment_Indexer_Struct_Async_02() + { + var source = @" +using System; +using System.Threading.Tasks; + +interface IMoveable +{ + int this[int i] {get;set;} +} + +struct Item : IMoveable +{ + public string Name {get; set;} + + public int this[int i] + { + get + { + Console.WriteLine(""Position get for item '{0}'"", Name); + return 0; + } + set + { + Console.WriteLine(""Position set for item '{0}'"", Name); + } + } +} + +class Program +{ + static async Task Main() + { + var item1 = new Item {Name = ""1""}; + await Shift1(item1); + + var item2 = new Item {Name = ""2""}; + await Shift2(item2); + } + + static async Task Shift1(T item) where T : struct, IMoveable + { + await Task.Yield(); + item[await GetOffsetAsync(GetOffset(ref item))] ++; + } + + static async Task Shift2(T item) where T : IMoveable + { + await Task.Yield(); + item[await GetOffsetAsync(GetOffset(ref item))] ++; + } + + static int value = 0; + static int GetOffset(ref T item) + { + item = (T)(IMoveable)new Item {Name = (--value).ToString()}; + return 0; + } + +#pragma warning disable CS1998 // This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. + static async Task GetOffsetAsync(int i) + { + return i; + } +} +"; + + var verifier = CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: @" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics(); + + verifier.VerifyIL("Program.d__1.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext", +@" +{ + // Code size 301 (0x12d) + .maxstack 4 + .locals init (int V_0, + System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter V_1, + System.Runtime.CompilerServices.YieldAwaitable V_2, + int V_3, + int V_4, + System.Runtime.CompilerServices.TaskAwaiter V_5, + System.Exception V_6) + IL_0000: ldarg.0 + IL_0001: ldfld ""int Program.d__1.<>1__state"" + IL_0006: stloc.0 + .try + { + IL_0007: ldloc.0 + IL_0008: brfalse.s IL_004b + IL_000a: ldloc.0 + IL_000b: ldc.i4.1 + IL_000c: beq IL_00af + IL_0011: call ""System.Runtime.CompilerServices.YieldAwaitable System.Threading.Tasks.Task.Yield()"" + IL_0016: stloc.2 + IL_0017: ldloca.s V_2 + IL_0019: call ""System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter System.Runtime.CompilerServices.YieldAwaitable.GetAwaiter()"" + IL_001e: stloc.1 + IL_001f: ldloca.s V_1 + IL_0021: call ""bool System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter.IsCompleted.get"" + IL_0026: brtrue.s IL_0067 + IL_0028: ldarg.0 + IL_0029: ldc.i4.0 + IL_002a: dup + IL_002b: stloc.0 + IL_002c: stfld ""int Program.d__1.<>1__state"" + IL_0031: ldarg.0 + IL_0032: ldloc.1 + IL_0033: stfld ""System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter Program.d__1.<>u__1"" + IL_0038: ldarg.0 + IL_0039: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_003e: ldloca.s V_1 + IL_0040: ldarg.0 + IL_0041: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.AwaitUnsafeOnCompletedd__1>(ref System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter, ref Program.d__1)"" + IL_0046: leave IL_012c + IL_004b: ldarg.0 + IL_004c: ldfld ""System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter Program.d__1.<>u__1"" + IL_0051: stloc.1 + IL_0052: ldarg.0 + IL_0053: ldflda ""System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter Program.d__1.<>u__1"" + IL_0058: initobj ""System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter"" + IL_005e: ldarg.0 + IL_005f: ldc.i4.m1 + IL_0060: dup + IL_0061: stloc.0 + IL_0062: stfld ""int Program.d__1.<>1__state"" + IL_0067: ldloca.s V_1 + IL_0069: call ""void System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter.GetResult()"" + IL_006e: ldarg.0 + IL_006f: ldflda ""T Program.d__1.item"" + IL_0074: call ""int Program.GetOffset(ref T)"" + IL_0079: call ""System.Threading.Tasks.Task Program.GetOffsetAsync(int)"" + IL_007e: callvirt ""System.Runtime.CompilerServices.TaskAwaiter System.Threading.Tasks.Task.GetAwaiter()"" + IL_0083: stloc.s V_5 + IL_0085: ldloca.s V_5 + IL_0087: call ""bool System.Runtime.CompilerServices.TaskAwaiter.IsCompleted.get"" + IL_008c: brtrue.s IL_00cc + IL_008e: ldarg.0 + IL_008f: ldc.i4.1 + IL_0090: dup + IL_0091: stloc.0 + IL_0092: stfld ""int Program.d__1.<>1__state"" + IL_0097: ldarg.0 + IL_0098: ldloc.s V_5 + IL_009a: stfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__2"" + IL_009f: ldarg.0 + IL_00a0: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_00a5: ldloca.s V_5 + IL_00a7: ldarg.0 + IL_00a8: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.AwaitUnsafeOnCompleted, Program.d__1>(ref System.Runtime.CompilerServices.TaskAwaiter, ref Program.d__1)"" + IL_00ad: leave.s IL_012c + IL_00af: ldarg.0 + IL_00b0: ldfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__2"" + IL_00b5: stloc.s V_5 + IL_00b7: ldarg.0 + IL_00b8: ldflda ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__2"" + IL_00bd: initobj ""System.Runtime.CompilerServices.TaskAwaiter"" + IL_00c3: ldarg.0 + IL_00c4: ldc.i4.m1 + IL_00c5: dup + IL_00c6: stloc.0 + IL_00c7: stfld ""int Program.d__1.<>1__state"" + IL_00cc: ldloca.s V_5 + IL_00ce: call ""int System.Runtime.CompilerServices.TaskAwaiter.GetResult()"" + IL_00d3: stloc.3 + IL_00d4: ldarg.0 + IL_00d5: ldflda ""T Program.d__1.item"" + IL_00da: ldloc.3 + IL_00db: constrained. ""T"" + IL_00e1: callvirt ""int IMoveable.this[int].get"" + IL_00e6: stloc.s V_4 + IL_00e8: ldarg.0 + IL_00e9: ldflda ""T Program.d__1.item"" + IL_00ee: ldloc.3 + IL_00ef: ldloc.s V_4 + IL_00f1: ldc.i4.1 + IL_00f2: add + IL_00f3: constrained. ""T"" + IL_00f9: callvirt ""void IMoveable.this[int].set"" + IL_00fe: leave.s IL_0119 + } + catch System.Exception + { + IL_0100: stloc.s V_6 + IL_0102: ldarg.0 + IL_0103: ldc.i4.s -2 + IL_0105: stfld ""int Program.d__1.<>1__state"" + IL_010a: ldarg.0 + IL_010b: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_0110: ldloc.s V_6 + IL_0112: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException(System.Exception)"" + IL_0117: leave.s IL_012c + } + IL_0119: ldarg.0 + IL_011a: ldc.i4.s -2 + IL_011c: stfld ""int Program.d__1.<>1__state"" + IL_0121: ldarg.0 + IL_0122: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_0127: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()"" + IL_012c: ret +} +"); + } + + [Fact] + [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] + [WorkItem("https://github.com/dotnet/roslyn/issues/70267")] + public void GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index_ThroughArray() + { + var source = @" +using System; + +interface IMoveable +{ + int this[int i] {get;set;} +} + +class Item : IMoveable +{ + public string Name {get; set;} + + public int this[int i] + { + get + { + Console.WriteLine(""Position get for item '{0}'"", Name); + return 0; + } + set + { + Console.WriteLine(""Position set for item '{0}'"", Name); + } + } +} + +class Item2 : Item {} + +class Program +{ + static void Main() + { + var item1 = new[] {new Item2 {Name = ""1""}}; + Shift1((Item[])item1); + + var item2 = new[] {new Item2 {Name = ""2""}}; + Shift2((Item[])item2); + } + + static void Shift1(T[] item) where T : class, IMoveable + { + item[GetArrayIndex()][GetOffset(ref item)] += 1; + } + + static void Shift2(T[] item) where T : IMoveable + { + item[GetArrayIndex()][GetOffset(ref item)] += 1; + } + + static int value = 0; + static int GetOffset(ref T[] item) + { + item[0] = (T)(IMoveable)new Item2 {Name = (--value).ToString()}; + return 0; + } + + static int GetArrayIndex() => 0; +} +"; + // Execution fails due to https://github.com/dotnet/roslyn/issues/70267 + var verifier = CompileAndVerify(source, options: TestOptions.ReleaseExe/*, expectedOutput: @" +Position get for item '1' +Position set for item '1' +Position get for item '2' +Position set for item '2' +"*/).VerifyDiagnostics(); + + verifier.VerifyIL("Program.Shift1", +@" +{ + // Code size 52 (0x34) + .maxstack 4 + .locals init (T& V_0, + T V_1, + int V_2) + IL_0000: ldarg.0 + IL_0001: call ""int Program.GetArrayIndex()"" + IL_0006: ldelem ""T"" + IL_000b: stloc.1 + IL_000c: ldloca.s V_1 + IL_000e: stloc.0 + IL_000f: ldarga.s V_0 + IL_0011: call ""int Program.GetOffset(ref T[])"" + IL_0016: stloc.2 + IL_0017: ldloc.0 + IL_0018: ldloc.2 + IL_0019: ldloc.0 + IL_001a: ldloc.2 + IL_001b: constrained. ""T"" + IL_0021: callvirt ""int IMoveable.this[int].get"" + IL_0026: ldc.i4.1 + IL_0027: add + IL_0028: constrained. ""T"" + IL_002e: callvirt ""void IMoveable.this[int].set"" + IL_0033: ret +} +"); + + verifier.VerifyIL("Program.Shift2", +@" +{ + // Code size 79 (0x4f) + .maxstack 4 + .locals init (T& V_0, + T V_1, + T& V_2, + int V_3, + T V_4) + IL_0000: ldarg.0 + IL_0001: call ""int Program.GetArrayIndex()"" + IL_0006: ldelema ""T"" + IL_000b: stloc.2 + IL_000c: ldloca.s V_4 + IL_000e: initobj ""T"" + IL_0014: ldloc.s V_4 + IL_0016: box ""T"" + IL_001b: brtrue.s IL_0028 + IL_001d: ldloc.2 + IL_001e: ldobj ""T"" + IL_0023: stloc.1 + IL_0024: ldloca.s V_1 + IL_0026: br.s IL_0029 + IL_0028: ldloc.2 + IL_0029: stloc.0 + IL_002a: ldarga.s V_0 + IL_002c: call ""int Program.GetOffset(ref T[])"" + IL_0031: stloc.3 + IL_0032: ldloc.0 + IL_0033: ldloc.3 + IL_0034: ldloc.0 + IL_0035: ldloc.3 + IL_0036: constrained. ""T"" + IL_003c: callvirt ""int IMoveable.this[int].get"" + IL_0041: ldc.i4.1 + IL_0042: add + IL_0043: constrained. ""T"" + IL_0049: callvirt ""void IMoveable.this[int].set"" + IL_004e: ret +} +"); + } + + [Fact] + [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] + public void GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index_ThroughArray() + { + var source = @" +using System; + +interface IMoveable +{ + int this[int i] {get;set;} +} + +struct Item : IMoveable +{ + public string Name {get; set;} + + public int this[int i] + { + get + { + Console.WriteLine(""Position get for item '{0}'"", Name); + return 0; + } + set + { + Console.WriteLine(""Position set for item '{0}'"", Name); + } + } +} + +class Program +{ + static void Main() + { + var item1 = new[] {new Item {Name = ""1""}}; + Shift1(item1); + + var item2 = new[] {new Item {Name = ""2""}}; + Shift2(item2); + } + + static void Shift1(T[] item) where T : struct, IMoveable + { + item[GetArrayIndex()][GetOffset(ref item)] += 1; + } + + static void Shift2(T[] item) where T : IMoveable + { + item[GetArrayIndex()][GetOffset(ref item)] += 1; + } + + static int value = 0; + static int GetOffset(ref T[] item) + { + item[0] = (T)(IMoveable)new Item {Name = (--value).ToString()}; + return 0; + } + + static int GetArrayIndex() => 0; +} +"; + + var verifier = CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: @" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics(); + + verifier.VerifyIL("Program.Shift1", +@" +{ + // Code size 49 (0x31) + .maxstack 4 + .locals init (T& V_0, + int V_1) + IL_0000: ldarg.0 + IL_0001: call ""int Program.GetArrayIndex()"" + IL_0006: ldelema ""T"" + IL_000b: stloc.0 + IL_000c: ldarga.s V_0 + IL_000e: call ""int Program.GetOffset(ref T[])"" + IL_0013: stloc.1 + IL_0014: ldloc.0 + IL_0015: ldloc.1 + IL_0016: ldloc.0 + IL_0017: ldloc.1 + IL_0018: constrained. ""T"" + IL_001e: callvirt ""int IMoveable.this[int].get"" + IL_0023: ldc.i4.1 + IL_0024: add + IL_0025: constrained. ""T"" + IL_002b: callvirt ""void IMoveable.this[int].set"" + IL_0030: ret +} +"); + } + + [Fact] + [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] + public void GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index_Async_01_ThroughArray() + { + var source = @" +using System; +using System.Threading.Tasks; + +interface IMoveable +{ + int this[int i] {get;set;} +} + +class Item : IMoveable +{ + public string Name {get; set;} + + public int this[int i] + { + get + { + Console.WriteLine(""Position get for item '{0}'"", Name); + return 0; + } + set + { + Console.WriteLine(""Position set for item '{0}'"", Name); + } + } +} + +class Item2 : Item {} + +class Program +{ + static async Task Main() + { + var item1 = new[] {new Item2 {Name = ""1""}}; + await Shift1((Item[])item1); + + var item2 = new[] {new Item2 {Name = ""2""}}; + await Shift2((Item[])item2); + } + + static async Task Shift1(T[] item) where T : class, IMoveable + { + item[GetArrayIndex()][await GetOffsetAsync(GetOffset(ref item))] += 1; + } + + static async Task Shift2(T[] item) where T : IMoveable + { + item[GetArrayIndex()][await GetOffsetAsync(GetOffset(ref item))] += 1; + } + + static int value = 0; + static int GetOffset(ref T[] item) + { + item[0] = (T)(IMoveable)new Item2 {Name = (--value).ToString()}; + return 0; + } + +#pragma warning disable CS1998 // This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. + static async Task GetOffsetAsync(int i) + { + return i; + } + + static int GetArrayIndex() => 0; +} +"; + + var verifier = CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: @" +Position get for item '1' +Position set for item '1' +Position get for item '2' +Position set for item '2' +").VerifyDiagnostics(); + + verifier.VerifyIL("Program.d__1.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext", +@" +{ + // Code size 227 (0xe3) + .maxstack 4 + .locals init (int V_0, + int V_1, + System.Runtime.CompilerServices.TaskAwaiter V_2, + System.Exception V_3) + IL_0000: ldarg.0 + IL_0001: ldfld ""int Program.d__1.<>1__state"" + IL_0006: stloc.0 + .try + { + IL_0007: ldloc.0 + IL_0008: brfalse.s IL_0062 + IL_000a: ldarg.0 + IL_000b: ldarg.0 + IL_000c: ldfld ""T[] Program.d__1.item"" + IL_0011: call ""int Program.GetArrayIndex()"" + IL_0016: ldelem ""T"" + IL_001b: stfld ""T Program.d__1.<>7__wrap1"" + IL_0020: ldarg.0 + IL_0021: ldflda ""T[] Program.d__1.item"" + IL_0026: call ""int Program.GetOffset(ref T[])"" + IL_002b: call ""System.Threading.Tasks.Task Program.GetOffsetAsync(int)"" + IL_0030: callvirt ""System.Runtime.CompilerServices.TaskAwaiter System.Threading.Tasks.Task.GetAwaiter()"" + IL_0035: stloc.2 + IL_0036: ldloca.s V_2 + IL_0038: call ""bool System.Runtime.CompilerServices.TaskAwaiter.IsCompleted.get"" + IL_003d: brtrue.s IL_007e + IL_003f: ldarg.0 + IL_0040: ldc.i4.0 + IL_0041: dup + IL_0042: stloc.0 + IL_0043: stfld ""int Program.d__1.<>1__state"" + IL_0048: ldarg.0 + IL_0049: ldloc.2 + IL_004a: stfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_004f: ldarg.0 + IL_0050: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_0055: ldloca.s V_2 + IL_0057: ldarg.0 + IL_0058: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.AwaitUnsafeOnCompleted, Program.d__1>(ref System.Runtime.CompilerServices.TaskAwaiter, ref Program.d__1)"" + IL_005d: leave IL_00e2 + IL_0062: ldarg.0 + IL_0063: ldfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_0068: stloc.2 + IL_0069: ldarg.0 + IL_006a: ldflda ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_006f: initobj ""System.Runtime.CompilerServices.TaskAwaiter"" + IL_0075: ldarg.0 + IL_0076: ldc.i4.m1 + IL_0077: dup + IL_0078: stloc.0 + IL_0079: stfld ""int Program.d__1.<>1__state"" + IL_007e: ldloca.s V_2 + IL_0080: call ""int System.Runtime.CompilerServices.TaskAwaiter.GetResult()"" + IL_0085: stloc.1 + IL_0086: ldarg.0 + IL_0087: ldfld ""T Program.d__1.<>7__wrap1"" + IL_008c: box ""T"" + IL_0091: ldloc.1 + IL_0092: ldarg.0 + IL_0093: ldfld ""T Program.d__1.<>7__wrap1"" + IL_0098: box ""T"" + IL_009d: ldloc.1 + IL_009e: callvirt ""int IMoveable.this[int].get"" + IL_00a3: ldc.i4.1 + IL_00a4: add + IL_00a5: callvirt ""void IMoveable.this[int].set"" + IL_00aa: ldarg.0 + IL_00ab: ldflda ""T Program.d__1.<>7__wrap1"" + IL_00b0: initobj ""T"" + IL_00b6: leave.s IL_00cf + } + catch System.Exception + { + IL_00b8: stloc.3 + IL_00b9: ldarg.0 + IL_00ba: ldc.i4.s -2 + IL_00bc: stfld ""int Program.d__1.<>1__state"" + IL_00c1: ldarg.0 + IL_00c2: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_00c7: ldloc.3 + IL_00c8: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException(System.Exception)"" + IL_00cd: leave.s IL_00e2 + } + IL_00cf: ldarg.0 + IL_00d0: ldc.i4.s -2 + IL_00d2: stfld ""int Program.d__1.<>1__state"" + IL_00d7: ldarg.0 + IL_00d8: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_00dd: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()"" + IL_00e2: ret +} +"); + + verifier.VerifyIL("Program.d__2.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext", +@" +{ + // Code size 397 (0x18d) + .maxstack 4 + .locals init (int V_0, + int V_1, + T V_2, + System.Runtime.CompilerServices.TaskAwaiter V_3, + System.Exception V_4) + IL_0000: ldarg.0 + IL_0001: ldfld ""int Program.d__2.<>1__state"" + IL_0006: stloc.0 + .try + { + IL_0007: ldloc.0 + IL_0008: brfalse IL_00b7 + IL_000d: ldarg.0 + IL_000e: ldarg.0 + IL_000f: ldfld ""T[] Program.d__2.item"" + IL_0014: stfld ""T[] Program.d__2.<>7__wrap2"" + IL_0019: ldarg.0 + IL_001a: call ""int Program.GetArrayIndex()"" + IL_001f: stfld ""int Program.d__2.<>7__wrap3"" + IL_0024: ldarg.0 + IL_0025: ldfld ""T[] Program.d__2.<>7__wrap2"" + IL_002a: ldarg.0 + IL_002b: ldfld ""int Program.d__2.<>7__wrap3"" + IL_0030: readonly. + IL_0032: ldelema ""T"" + IL_0037: pop + IL_0038: ldloca.s V_2 + IL_003a: initobj ""T"" + IL_0040: ldloc.2 + IL_0041: box ""T"" + IL_0046: brtrue.s IL_0061 + IL_0048: ldarg.0 + IL_0049: ldarg.0 + IL_004a: ldfld ""T[] Program.d__2.<>7__wrap2"" + IL_004f: ldarg.0 + IL_0050: ldfld ""int Program.d__2.<>7__wrap3"" + IL_0055: ldelem ""T"" + IL_005a: stfld ""T Program.d__2.<>7__wrap1"" + IL_005f: br.s IL_0075 + IL_0061: ldarg.0 + IL_0062: ldfld ""T[] Program.d__2.<>7__wrap2"" + IL_0067: ldarg.0 + IL_0068: ldfld ""int Program.d__2.<>7__wrap3"" + IL_006d: readonly. + IL_006f: ldelema ""T"" + IL_0074: pop + IL_0075: ldarg.0 + IL_0076: ldflda ""T[] Program.d__2.item"" + IL_007b: call ""int Program.GetOffset(ref T[])"" + IL_0080: call ""System.Threading.Tasks.Task Program.GetOffsetAsync(int)"" + IL_0085: callvirt ""System.Runtime.CompilerServices.TaskAwaiter System.Threading.Tasks.Task.GetAwaiter()"" + IL_008a: stloc.3 + IL_008b: ldloca.s V_3 + IL_008d: call ""bool System.Runtime.CompilerServices.TaskAwaiter.IsCompleted.get"" + IL_0092: brtrue.s IL_00d3 + IL_0094: ldarg.0 + IL_0095: ldc.i4.0 + IL_0096: dup + IL_0097: stloc.0 + IL_0098: stfld ""int Program.d__2.<>1__state"" + IL_009d: ldarg.0 + IL_009e: ldloc.3 + IL_009f: stfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__2.<>u__1"" + IL_00a4: ldarg.0 + IL_00a5: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__2.<>t__builder"" + IL_00aa: ldloca.s V_3 + IL_00ac: ldarg.0 + IL_00ad: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.AwaitUnsafeOnCompleted, Program.d__2>(ref System.Runtime.CompilerServices.TaskAwaiter, ref Program.d__2)"" + IL_00b2: leave IL_018c + IL_00b7: ldarg.0 + IL_00b8: ldfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__2.<>u__1"" + IL_00bd: stloc.3 + IL_00be: ldarg.0 + IL_00bf: ldflda ""System.Runtime.CompilerServices.TaskAwaiter Program.d__2.<>u__1"" + IL_00c4: initobj ""System.Runtime.CompilerServices.TaskAwaiter"" + IL_00ca: ldarg.0 + IL_00cb: ldc.i4.m1 + IL_00cc: dup + IL_00cd: stloc.0 + IL_00ce: stfld ""int Program.d__2.<>1__state"" + IL_00d3: ldloca.s V_3 + IL_00d5: call ""int System.Runtime.CompilerServices.TaskAwaiter.GetResult()"" + IL_00da: stloc.1 + IL_00db: ldloca.s V_2 + IL_00dd: initobj ""T"" + IL_00e3: ldloc.2 + IL_00e4: box ""T"" + IL_00e9: brtrue.s IL_00f3 + IL_00eb: ldarg.0 + IL_00ec: ldflda ""T Program.d__2.<>7__wrap1"" + IL_00f1: br.s IL_0106 + IL_00f3: ldarg.0 + IL_00f4: ldfld ""T[] Program.d__2.<>7__wrap2"" + IL_00f9: ldarg.0 + IL_00fa: ldfld ""int Program.d__2.<>7__wrap3"" + IL_00ff: readonly. + IL_0101: ldelema ""T"" + IL_0106: ldloc.1 + IL_0107: ldloca.s V_2 + IL_0109: initobj ""T"" + IL_010f: ldloc.2 + IL_0110: box ""T"" + IL_0115: brtrue.s IL_011f + IL_0117: ldarg.0 + IL_0118: ldflda ""T Program.d__2.<>7__wrap1"" + IL_011d: br.s IL_0132 + IL_011f: ldarg.0 + IL_0120: ldfld ""T[] Program.d__2.<>7__wrap2"" + IL_0125: ldarg.0 + IL_0126: ldfld ""int Program.d__2.<>7__wrap3"" + IL_012b: readonly. + IL_012d: ldelema ""T"" + IL_0132: ldloc.1 + IL_0133: constrained. ""T"" + IL_0139: callvirt ""int IMoveable.this[int].get"" + IL_013e: ldc.i4.1 + IL_013f: add + IL_0140: constrained. ""T"" + IL_0146: callvirt ""void IMoveable.this[int].set"" + IL_014b: ldarg.0 + IL_014c: ldflda ""T Program.d__2.<>7__wrap1"" + IL_0151: initobj ""T"" + IL_0157: ldarg.0 + IL_0158: ldnull + IL_0159: stfld ""T[] Program.d__2.<>7__wrap2"" + IL_015e: leave.s IL_0179 + } + catch System.Exception + { + IL_0160: stloc.s V_4 + IL_0162: ldarg.0 + IL_0163: ldc.i4.s -2 + IL_0165: stfld ""int Program.d__2.<>1__state"" + IL_016a: ldarg.0 + IL_016b: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__2.<>t__builder"" + IL_0170: ldloc.s V_4 + IL_0172: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException(System.Exception)"" + IL_0177: leave.s IL_018c + } + IL_0179: ldarg.0 + IL_017a: ldc.i4.s -2 + IL_017c: stfld ""int Program.d__2.<>1__state"" + IL_0181: ldarg.0 + IL_0182: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__2.<>t__builder"" + IL_0187: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()"" + IL_018c: ret +} +"); + } + + [Fact] + [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] + public void GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index_Async_01_ThroughArray() + { + var source = @" +using System; +using System.Threading.Tasks; + +interface IMoveable +{ + int this[int i] {get;set;} +} + +struct Item : IMoveable +{ + public string Name {get; set;} + + public int this[int i] + { + get + { + Console.WriteLine(""Position get for item '{0}'"", Name); + return 0; + } + set + { + Console.WriteLine(""Position set for item '{0}'"", Name); + } + } +} + +class Program +{ + static async Task Main() + { + var item1 = new[] {new Item {Name = ""1""}}; + await Shift1(item1); + + var item2 = new[] {new Item {Name = ""2""}}; + await Shift2(item2); + } + + static async Task Shift1(T[] item) where T : struct, IMoveable + { + item[GetArrayIndex()][await GetOffsetAsync(GetOffset(ref item))] += 1; + } + + static async Task Shift2(T[] item) where T : IMoveable + { + item[GetArrayIndex()][await GetOffsetAsync(GetOffset(ref item))] += 1; + } + + static int value = 0; + static int GetOffset(ref T[] item) + { + item[0] = (T)(IMoveable)new Item {Name = (--value).ToString()}; + return 0; + } + +#pragma warning disable CS1998 // This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. + static async Task GetOffsetAsync(int i) + { + return i; + } + + static int GetArrayIndex() => 0; +} +"; + + var verifier = CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: @" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics(); + + verifier.VerifyIL("Program.d__1.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext", +@" +{ + // Code size 271 (0x10f) + .maxstack 4 + .locals init (int V_0, + int V_1, + System.Runtime.CompilerServices.TaskAwaiter V_2, + System.Exception V_3) + IL_0000: ldarg.0 + IL_0001: ldfld ""int Program.d__1.<>1__state"" + IL_0006: stloc.0 + .try + { + IL_0007: ldloc.0 + IL_0008: brfalse.s IL_0077 + IL_000a: ldarg.0 + IL_000b: ldarg.0 + IL_000c: ldfld ""T[] Program.d__1.item"" + IL_0011: stfld ""T[] Program.d__1.<>7__wrap1"" + IL_0016: ldarg.0 + IL_0017: call ""int Program.GetArrayIndex()"" + IL_001c: stfld ""int Program.d__1.<>7__wrap2"" + IL_0021: ldarg.0 + IL_0022: ldfld ""T[] Program.d__1.<>7__wrap1"" + IL_0027: ldarg.0 + IL_0028: ldfld ""int Program.d__1.<>7__wrap2"" + IL_002d: readonly. + IL_002f: ldelema ""T"" + IL_0034: pop + IL_0035: ldarg.0 + IL_0036: ldflda ""T[] Program.d__1.item"" + IL_003b: call ""int Program.GetOffset(ref T[])"" + IL_0040: call ""System.Threading.Tasks.Task Program.GetOffsetAsync(int)"" + IL_0045: callvirt ""System.Runtime.CompilerServices.TaskAwaiter System.Threading.Tasks.Task.GetAwaiter()"" + IL_004a: stloc.2 + IL_004b: ldloca.s V_2 + IL_004d: call ""bool System.Runtime.CompilerServices.TaskAwaiter.IsCompleted.get"" + IL_0052: brtrue.s IL_0093 + IL_0054: ldarg.0 + IL_0055: ldc.i4.0 + IL_0056: dup + IL_0057: stloc.0 + IL_0058: stfld ""int Program.d__1.<>1__state"" + IL_005d: ldarg.0 + IL_005e: ldloc.2 + IL_005f: stfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_0064: ldarg.0 + IL_0065: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_006a: ldloca.s V_2 + IL_006c: ldarg.0 + IL_006d: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.AwaitUnsafeOnCompleted, Program.d__1>(ref System.Runtime.CompilerServices.TaskAwaiter, ref Program.d__1)"" + IL_0072: leave IL_010e + IL_0077: ldarg.0 + IL_0078: ldfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_007d: stloc.2 + IL_007e: ldarg.0 + IL_007f: ldflda ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_0084: initobj ""System.Runtime.CompilerServices.TaskAwaiter"" + IL_008a: ldarg.0 + IL_008b: ldc.i4.m1 + IL_008c: dup + IL_008d: stloc.0 + IL_008e: stfld ""int Program.d__1.<>1__state"" + IL_0093: ldloca.s V_2 + IL_0095: call ""int System.Runtime.CompilerServices.TaskAwaiter.GetResult()"" + IL_009a: stloc.1 + IL_009b: ldarg.0 + IL_009c: ldfld ""T[] Program.d__1.<>7__wrap1"" + IL_00a1: ldarg.0 + IL_00a2: ldfld ""int Program.d__1.<>7__wrap2"" + IL_00a7: readonly. + IL_00a9: ldelema ""T"" + IL_00ae: ldloc.1 + IL_00af: ldarg.0 + IL_00b0: ldfld ""T[] Program.d__1.<>7__wrap1"" + IL_00b5: ldarg.0 + IL_00b6: ldfld ""int Program.d__1.<>7__wrap2"" + IL_00bb: readonly. + IL_00bd: ldelema ""T"" + IL_00c2: ldloc.1 + IL_00c3: constrained. ""T"" + IL_00c9: callvirt ""int IMoveable.this[int].get"" + IL_00ce: ldc.i4.1 + IL_00cf: add + IL_00d0: constrained. ""T"" + IL_00d6: callvirt ""void IMoveable.this[int].set"" + IL_00db: ldarg.0 + IL_00dc: ldnull + IL_00dd: stfld ""T[] Program.d__1.<>7__wrap1"" + IL_00e2: leave.s IL_00fb + } + catch System.Exception + { + IL_00e4: stloc.3 + IL_00e5: ldarg.0 + IL_00e6: ldc.i4.s -2 + IL_00e8: stfld ""int Program.d__1.<>1__state"" + IL_00ed: ldarg.0 + IL_00ee: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_00f3: ldloc.3 + IL_00f4: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException(System.Exception)"" + IL_00f9: leave.s IL_010e + } + IL_00fb: ldarg.0 + IL_00fc: ldc.i4.s -2 + IL_00fe: stfld ""int Program.d__1.<>1__state"" + IL_0103: ldarg.0 + IL_0104: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_0109: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()"" + IL_010e: ret +} +"); + } + + [Fact] + [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] + [WorkItem("https://github.com/dotnet/roslyn/issues/70267")] + public void GenericTypeParameterAsReceiver_Increment_Indexer_Class_ThroughArray() + { + var source = @" +using System; + +interface IMoveable +{ + int this[int i] {get;set;} +} + +class Item : IMoveable +{ + public string Name {get; set;} + + public int this[int i] + { + get + { + Console.WriteLine(""Position get for item '{0}'"", Name); + return 0; + } + set + { + Console.WriteLine(""Position set for item '{0}'"", Name); + } + } +} + +class Item2 : Item {} + +class Program +{ + static void Main() + { + var item1 = new[] {new Item2 {Name = ""1""}}; + Shift1((Item[])item1); + + var item2 = new[] {new Item2 {Name = ""2""}}; + Shift2((Item[])item2); + } + + static void Shift1(T[] item) where T : class, IMoveable + { + item[GetArrayIndex()][GetOffset(ref item)] ++; + } + + static void Shift2(T[] item) where T : IMoveable + { + item[GetArrayIndex()][GetOffset(ref item)] ++; + } + + static int value = 0; + static int GetOffset(ref T[] item) + { + item[0] = (T)(IMoveable)new Item2 {Name = (--value).ToString()}; + return 0; + } + + static int GetArrayIndex() => 0; +} +"; + // Execution fails due to https://github.com/dotnet/roslyn/issues/70267 + var verifier = CompileAndVerify(source, options: TestOptions.ReleaseExe/*, expectedOutput: @" +Position get for item '1' +Position set for item '1' +Position get for item '2' +Position set for item '2' +"*/).VerifyDiagnostics(); + + verifier.VerifyIL("Program.Shift1", +@" +{ + // Code size 52 (0x34) + .maxstack 4 + .locals init (T V_0, + int V_1, + int V_2) + IL_0000: ldarg.0 + IL_0001: call ""int Program.GetArrayIndex()"" + IL_0006: ldelem ""T"" + IL_000b: stloc.0 + IL_000c: ldloca.s V_0 + IL_000e: ldarga.s V_0 + IL_0010: call ""int Program.GetOffset(ref T[])"" + IL_0015: stloc.1 + IL_0016: dup + IL_0017: ldloc.1 + IL_0018: constrained. ""T"" + IL_001e: callvirt ""int IMoveable.this[int].get"" + IL_0023: stloc.2 + IL_0024: ldloc.1 + IL_0025: ldloc.2 + IL_0026: ldc.i4.1 + IL_0027: add + IL_0028: constrained. ""T"" + IL_002e: callvirt ""void IMoveable.this[int].set"" + IL_0033: ret +} +"); + + verifier.VerifyIL("Program.Shift2", +@" +{ + // Code size 79 (0x4f) + .maxstack 4 + .locals init (T V_0, + T& V_1, + int V_2, + int V_3, + T V_4) + IL_0000: ldarg.0 + IL_0001: call ""int Program.GetArrayIndex()"" + IL_0006: ldelema ""T"" + IL_000b: stloc.1 + IL_000c: ldloca.s V_4 + IL_000e: initobj ""T"" + IL_0014: ldloc.s V_4 + IL_0016: box ""T"" + IL_001b: brtrue.s IL_0028 + IL_001d: ldloc.1 + IL_001e: ldobj ""T"" + IL_0023: stloc.0 + IL_0024: ldloca.s V_0 + IL_0026: br.s IL_0029 + IL_0028: ldloc.1 + IL_0029: ldarga.s V_0 + IL_002b: call ""int Program.GetOffset(ref T[])"" + IL_0030: stloc.2 + IL_0031: dup + IL_0032: ldloc.2 + IL_0033: constrained. ""T"" + IL_0039: callvirt ""int IMoveable.this[int].get"" + IL_003e: stloc.3 + IL_003f: ldloc.2 + IL_0040: ldloc.3 + IL_0041: ldc.i4.1 + IL_0042: add + IL_0043: constrained. ""T"" + IL_0049: callvirt ""void IMoveable.this[int].set"" + IL_004e: ret +} +"); + } + + [Fact] + [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] + public void GenericTypeParameterAsReceiver_Increment_Indexer_Struct_ThroughArray() + { + var source = @" +using System; + +interface IMoveable +{ + int this[int i] {get;set;} +} + +struct Item : IMoveable +{ + public string Name {get; set;} + + public int this[int i] + { + get + { + Console.WriteLine(""Position get for item '{0}'"", Name); + return 0; + } + set + { + Console.WriteLine(""Position set for item '{0}'"", Name); + } + } +} + +class Program +{ + static void Main() + { + var item1 = new[] {new Item {Name = ""1""}}; + Shift1(item1); + + var item2 = new[] {new Item {Name = ""2""}}; + Shift2(item2); + } + + static void Shift1(T[] item) where T : struct, IMoveable + { + item[GetArrayIndex()][GetOffset(ref item)] ++; + } + + static void Shift2(T[] item) where T : IMoveable + { + item[GetArrayIndex()][GetOffset(ref item)] ++; + } + + static int value = 0; + static int GetOffset(ref T[] item) + { + item[0] = (T)(IMoveable)new Item {Name = (--value).ToString()}; + return 0; + } + + static int GetArrayIndex() => 0; +} +"; + + var verifier = CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: @" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics(); + + verifier.VerifyIL("Program.Shift1", +@" +{ + // Code size 49 (0x31) + .maxstack 4 + .locals init (int V_0, + int V_1) + IL_0000: ldarg.0 + IL_0001: call ""int Program.GetArrayIndex()"" + IL_0006: ldelema ""T"" + IL_000b: ldarga.s V_0 + IL_000d: call ""int Program.GetOffset(ref T[])"" + IL_0012: stloc.0 + IL_0013: dup + IL_0014: ldloc.0 + IL_0015: constrained. ""T"" + IL_001b: callvirt ""int IMoveable.this[int].get"" + IL_0020: stloc.1 + IL_0021: ldloc.0 + IL_0022: ldloc.1 + IL_0023: ldc.i4.1 + IL_0024: add + IL_0025: constrained. ""T"" + IL_002b: callvirt ""void IMoveable.this[int].set"" + IL_0030: ret +} +"); + } + + [Fact] + [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] + public void GenericTypeParameterAsReceiver_Increment_Indexer_Class_Async_01_ThroughArray() + { + var source = @" +using System; +using System.Threading.Tasks; + +interface IMoveable +{ + int this[int i] {get;set;} +} + +class Item : IMoveable +{ + public string Name {get; set;} + + public int this[int i] + { + get + { + Console.WriteLine(""Position get for item '{0}'"", Name); + return 0; + } + set + { + Console.WriteLine(""Position set for item '{0}'"", Name); + } + } +} + +class Item2 : Item {} + +class Program +{ + static async Task Main() + { + var item1 = new[] {new Item2 {Name = ""1""}}; + await Shift1((Item[])item1); + + var item2 = new[] {new Item2 {Name = ""2""}}; + await Shift2((Item[])item2); + } + + static async Task Shift1(T[] item) where T : class, IMoveable + { + item[GetArrayIndex()][await GetOffsetAsync(GetOffset(ref item))] ++; + } + + static async Task Shift2(T[] item) where T : IMoveable + { + item[GetArrayIndex()][await GetOffsetAsync(GetOffset(ref item))] ++; + } + + static int value = 0; + static int GetOffset(ref T[] item) + { + item[0] = (T)(IMoveable)new Item2 {Name = (--value).ToString()}; + return 0; + } + +#pragma warning disable CS1998 // This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. + static async Task GetOffsetAsync(int i) + { + return i; + } + + static int GetArrayIndex() => 0; +} +"; + + var verifier = CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: @" +Position get for item '1' +Position set for item '1' +Position get for item '2' +Position set for item '2' +").VerifyDiagnostics(); + + verifier.VerifyIL("Program.d__1.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext", +@" +{ + // Code size 231 (0xe7) + .maxstack 4 + .locals init (int V_0, + int V_1, + int V_2, + System.Runtime.CompilerServices.TaskAwaiter V_3, + System.Exception V_4) + IL_0000: ldarg.0 + IL_0001: ldfld ""int Program.d__1.<>1__state"" + IL_0006: stloc.0 + .try + { + IL_0007: ldloc.0 + IL_0008: brfalse.s IL_0062 + IL_000a: ldarg.0 + IL_000b: ldarg.0 + IL_000c: ldfld ""T[] Program.d__1.item"" + IL_0011: call ""int Program.GetArrayIndex()"" + IL_0016: ldelem ""T"" + IL_001b: stfld ""T Program.d__1.<>7__wrap1"" + IL_0020: ldarg.0 + IL_0021: ldflda ""T[] Program.d__1.item"" + IL_0026: call ""int Program.GetOffset(ref T[])"" + IL_002b: call ""System.Threading.Tasks.Task Program.GetOffsetAsync(int)"" + IL_0030: callvirt ""System.Runtime.CompilerServices.TaskAwaiter System.Threading.Tasks.Task.GetAwaiter()"" + IL_0035: stloc.3 + IL_0036: ldloca.s V_3 + IL_0038: call ""bool System.Runtime.CompilerServices.TaskAwaiter.IsCompleted.get"" + IL_003d: brtrue.s IL_007e + IL_003f: ldarg.0 + IL_0040: ldc.i4.0 + IL_0041: dup + IL_0042: stloc.0 + IL_0043: stfld ""int Program.d__1.<>1__state"" + IL_0048: ldarg.0 + IL_0049: ldloc.3 + IL_004a: stfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_004f: ldarg.0 + IL_0050: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_0055: ldloca.s V_3 + IL_0057: ldarg.0 + IL_0058: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.AwaitUnsafeOnCompleted, Program.d__1>(ref System.Runtime.CompilerServices.TaskAwaiter, ref Program.d__1)"" + IL_005d: leave IL_00e6 + IL_0062: ldarg.0 + IL_0063: ldfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_0068: stloc.3 + IL_0069: ldarg.0 + IL_006a: ldflda ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_006f: initobj ""System.Runtime.CompilerServices.TaskAwaiter"" + IL_0075: ldarg.0 + IL_0076: ldc.i4.m1 + IL_0077: dup + IL_0078: stloc.0 + IL_0079: stfld ""int Program.d__1.<>1__state"" + IL_007e: ldloca.s V_3 + IL_0080: call ""int System.Runtime.CompilerServices.TaskAwaiter.GetResult()"" + IL_0085: stloc.1 + IL_0086: ldarg.0 + IL_0087: ldfld ""T Program.d__1.<>7__wrap1"" + IL_008c: box ""T"" + IL_0091: ldloc.1 + IL_0092: callvirt ""int IMoveable.this[int].get"" + IL_0097: stloc.2 + IL_0098: ldarg.0 + IL_0099: ldfld ""T Program.d__1.<>7__wrap1"" + IL_009e: box ""T"" + IL_00a3: ldloc.1 + IL_00a4: ldloc.2 + IL_00a5: ldc.i4.1 + IL_00a6: add + IL_00a7: callvirt ""void IMoveable.this[int].set"" + IL_00ac: ldarg.0 + IL_00ad: ldflda ""T Program.d__1.<>7__wrap1"" + IL_00b2: initobj ""T"" + IL_00b8: leave.s IL_00d3 + } + catch System.Exception + { + IL_00ba: stloc.s V_4 + IL_00bc: ldarg.0 + IL_00bd: ldc.i4.s -2 + IL_00bf: stfld ""int Program.d__1.<>1__state"" + IL_00c4: ldarg.0 + IL_00c5: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_00ca: ldloc.s V_4 + IL_00cc: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException(System.Exception)"" + IL_00d1: leave.s IL_00e6 + } + IL_00d3: ldarg.0 + IL_00d4: ldc.i4.s -2 + IL_00d6: stfld ""int Program.d__1.<>1__state"" + IL_00db: ldarg.0 + IL_00dc: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_00e1: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()"" + IL_00e6: ret +} +"); + + verifier.VerifyIL("Program.d__2.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext", +@" +{ + // Code size 402 (0x192) + .maxstack 4 + .locals init (int V_0, + int V_1, + int V_2, + T V_3, + System.Runtime.CompilerServices.TaskAwaiter V_4, + System.Exception V_5) + IL_0000: ldarg.0 + IL_0001: ldfld ""int Program.d__2.<>1__state"" + IL_0006: stloc.0 + .try + { + IL_0007: ldloc.0 + IL_0008: brfalse IL_00b9 + IL_000d: ldarg.0 + IL_000e: ldarg.0 + IL_000f: ldfld ""T[] Program.d__2.item"" + IL_0014: stfld ""T[] Program.d__2.<>7__wrap2"" + IL_0019: ldarg.0 + IL_001a: call ""int Program.GetArrayIndex()"" + IL_001f: stfld ""int Program.d__2.<>7__wrap3"" + IL_0024: ldarg.0 + IL_0025: ldfld ""T[] Program.d__2.<>7__wrap2"" + IL_002a: ldarg.0 + IL_002b: ldfld ""int Program.d__2.<>7__wrap3"" + IL_0030: readonly. + IL_0032: ldelema ""T"" + IL_0037: pop + IL_0038: ldloca.s V_3 + IL_003a: initobj ""T"" + IL_0040: ldloc.3 + IL_0041: box ""T"" + IL_0046: brtrue.s IL_0061 + IL_0048: ldarg.0 + IL_0049: ldarg.0 + IL_004a: ldfld ""T[] Program.d__2.<>7__wrap2"" + IL_004f: ldarg.0 + IL_0050: ldfld ""int Program.d__2.<>7__wrap3"" + IL_0055: ldelem ""T"" + IL_005a: stfld ""T Program.d__2.<>7__wrap1"" + IL_005f: br.s IL_0075 + IL_0061: ldarg.0 + IL_0062: ldfld ""T[] Program.d__2.<>7__wrap2"" + IL_0067: ldarg.0 + IL_0068: ldfld ""int Program.d__2.<>7__wrap3"" + IL_006d: readonly. + IL_006f: ldelema ""T"" + IL_0074: pop + IL_0075: ldarg.0 + IL_0076: ldflda ""T[] Program.d__2.item"" + IL_007b: call ""int Program.GetOffset(ref T[])"" + IL_0080: call ""System.Threading.Tasks.Task Program.GetOffsetAsync(int)"" + IL_0085: callvirt ""System.Runtime.CompilerServices.TaskAwaiter System.Threading.Tasks.Task.GetAwaiter()"" + IL_008a: stloc.s V_4 + IL_008c: ldloca.s V_4 + IL_008e: call ""bool System.Runtime.CompilerServices.TaskAwaiter.IsCompleted.get"" + IL_0093: brtrue.s IL_00d6 + IL_0095: ldarg.0 + IL_0096: ldc.i4.0 + IL_0097: dup + IL_0098: stloc.0 + IL_0099: stfld ""int Program.d__2.<>1__state"" + IL_009e: ldarg.0 + IL_009f: ldloc.s V_4 + IL_00a1: stfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__2.<>u__1"" + IL_00a6: ldarg.0 + IL_00a7: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__2.<>t__builder"" + IL_00ac: ldloca.s V_4 + IL_00ae: ldarg.0 + IL_00af: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.AwaitUnsafeOnCompleted, Program.d__2>(ref System.Runtime.CompilerServices.TaskAwaiter, ref Program.d__2)"" + IL_00b4: leave IL_0191 + IL_00b9: ldarg.0 + IL_00ba: ldfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__2.<>u__1"" + IL_00bf: stloc.s V_4 + IL_00c1: ldarg.0 + IL_00c2: ldflda ""System.Runtime.CompilerServices.TaskAwaiter Program.d__2.<>u__1"" + IL_00c7: initobj ""System.Runtime.CompilerServices.TaskAwaiter"" + IL_00cd: ldarg.0 + IL_00ce: ldc.i4.m1 + IL_00cf: dup + IL_00d0: stloc.0 + IL_00d1: stfld ""int Program.d__2.<>1__state"" + IL_00d6: ldloca.s V_4 + IL_00d8: call ""int System.Runtime.CompilerServices.TaskAwaiter.GetResult()"" + IL_00dd: stloc.1 + IL_00de: ldloca.s V_3 + IL_00e0: initobj ""T"" + IL_00e6: ldloc.3 + IL_00e7: box ""T"" + IL_00ec: brtrue.s IL_00f6 + IL_00ee: ldarg.0 + IL_00ef: ldflda ""T Program.d__2.<>7__wrap1"" + IL_00f4: br.s IL_0109 + IL_00f6: ldarg.0 + IL_00f7: ldfld ""T[] Program.d__2.<>7__wrap2"" + IL_00fc: ldarg.0 + IL_00fd: ldfld ""int Program.d__2.<>7__wrap3"" + IL_0102: readonly. + IL_0104: ldelema ""T"" + IL_0109: ldloc.1 + IL_010a: constrained. ""T"" + IL_0110: callvirt ""int IMoveable.this[int].get"" + IL_0115: stloc.2 + IL_0116: ldloca.s V_3 + IL_0118: initobj ""T"" + IL_011e: ldloc.3 + IL_011f: box ""T"" + IL_0124: brtrue.s IL_012e + IL_0126: ldarg.0 + IL_0127: ldflda ""T Program.d__2.<>7__wrap1"" + IL_012c: br.s IL_0141 + IL_012e: ldarg.0 + IL_012f: ldfld ""T[] Program.d__2.<>7__wrap2"" + IL_0134: ldarg.0 + IL_0135: ldfld ""int Program.d__2.<>7__wrap3"" + IL_013a: readonly. + IL_013c: ldelema ""T"" + IL_0141: ldloc.1 + IL_0142: ldloc.2 + IL_0143: ldc.i4.1 + IL_0144: add + IL_0145: constrained. ""T"" + IL_014b: callvirt ""void IMoveable.this[int].set"" + IL_0150: ldarg.0 + IL_0151: ldflda ""T Program.d__2.<>7__wrap1"" + IL_0156: initobj ""T"" + IL_015c: ldarg.0 + IL_015d: ldnull + IL_015e: stfld ""T[] Program.d__2.<>7__wrap2"" + IL_0163: leave.s IL_017e } catch System.Exception { - IL_015e: stloc.s V_7 - IL_0160: ldarg.0 - IL_0161: ldc.i4.s -2 - IL_0163: stfld ""int Program.d__2.<>1__state"" - IL_0168: ldarg.0 - IL_0169: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__2.<>t__builder"" - IL_016e: ldloc.s V_7 - IL_0170: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException(System.Exception)"" - IL_0175: leave.s IL_018a + IL_0165: stloc.s V_5 + IL_0167: ldarg.0 + IL_0168: ldc.i4.s -2 + IL_016a: stfld ""int Program.d__2.<>1__state"" + IL_016f: ldarg.0 + IL_0170: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__2.<>t__builder"" + IL_0175: ldloc.s V_5 + IL_0177: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException(System.Exception)"" + IL_017c: leave.s IL_0191 } - IL_0177: ldarg.0 - IL_0178: ldc.i4.s -2 - IL_017a: stfld ""int Program.d__2.<>1__state"" - IL_017f: ldarg.0 - IL_0180: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__2.<>t__builder"" - IL_0185: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()"" - IL_018a: ret + IL_017e: ldarg.0 + IL_017f: ldc.i4.s -2 + IL_0181: stfld ""int Program.d__2.<>1__state"" + IL_0186: ldarg.0 + IL_0187: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__2.<>t__builder"" + IL_018c: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()"" + IL_0191: ret } "); } [Fact] [WorkItem(63221, "https://github.com/dotnet/roslyn/issues/63221")] - public void GenericTypeParameterAsReceiver_Increment_Indexer_Struct_Async_02() + public void GenericTypeParameterAsReceiver_Increment_Indexer_Struct_Async_01_ThroughArray() { var source = @" using System; @@ -8698,29 +10713,27 @@ class Program { static async Task Main() { - var item1 = new Item {Name = ""1""}; + var item1 = new[] {new Item {Name = ""1""}}; await Shift1(item1); - var item2 = new Item {Name = ""2""}; + var item2 = new[] {new Item {Name = ""2""}}; await Shift2(item2); } - static async Task Shift1(T item) where T : struct, IMoveable + static async Task Shift1(T[] item) where T : struct, IMoveable { - await Task.Yield(); - item[await GetOffsetAsync(GetOffset(ref item))] ++; + item[GetArrayIndex()][await GetOffsetAsync(GetOffset(ref item))] ++; } - static async Task Shift2(T item) where T : IMoveable + static async Task Shift2(T[] item) where T : IMoveable { - await Task.Yield(); - item[await GetOffsetAsync(GetOffset(ref item))] ++; + item[GetArrayIndex()][await GetOffsetAsync(GetOffset(ref item))] ++; } static int value = 0; - static int GetOffset(ref T item) + static int GetOffset(ref T[] item) { - item = (T)(IMoveable)new Item {Name = (--value).ToString()}; + item[0] = (T)(IMoveable)new Item {Name = (--value).ToString()}; return 0; } @@ -8729,6 +10742,8 @@ static async Task GetOffsetAsync(int i) { return i; } + + static int GetArrayIndex() => 0; } "; @@ -8742,132 +10757,117 @@ static async Task GetOffsetAsync(int i) verifier.VerifyIL("Program.d__1.System.Runtime.CompilerServices.IAsyncStateMachine.MoveNext", @" { - // Code size 301 (0x12d) + // Code size 275 (0x113) .maxstack 4 .locals init (int V_0, - System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter V_1, - System.Runtime.CompilerServices.YieldAwaitable V_2, - int V_3, - int V_4, - System.Runtime.CompilerServices.TaskAwaiter V_5, - System.Exception V_6) + int V_1, + int V_2, + System.Runtime.CompilerServices.TaskAwaiter V_3, + System.Exception V_4) IL_0000: ldarg.0 IL_0001: ldfld ""int Program.d__1.<>1__state"" IL_0006: stloc.0 .try { IL_0007: ldloc.0 - IL_0008: brfalse.s IL_004b - IL_000a: ldloc.0 - IL_000b: ldc.i4.1 - IL_000c: beq IL_00af - IL_0011: call ""System.Runtime.CompilerServices.YieldAwaitable System.Threading.Tasks.Task.Yield()"" - IL_0016: stloc.2 - IL_0017: ldloca.s V_2 - IL_0019: call ""System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter System.Runtime.CompilerServices.YieldAwaitable.GetAwaiter()"" - IL_001e: stloc.1 - IL_001f: ldloca.s V_1 - IL_0021: call ""bool System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter.IsCompleted.get"" - IL_0026: brtrue.s IL_0067 - IL_0028: ldarg.0 - IL_0029: ldc.i4.0 - IL_002a: dup - IL_002b: stloc.0 - IL_002c: stfld ""int Program.d__1.<>1__state"" - IL_0031: ldarg.0 - IL_0032: ldloc.1 - IL_0033: stfld ""System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter Program.d__1.<>u__1"" - IL_0038: ldarg.0 - IL_0039: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" - IL_003e: ldloca.s V_1 - IL_0040: ldarg.0 - IL_0041: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.AwaitUnsafeOnCompletedd__1>(ref System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter, ref Program.d__1)"" - IL_0046: leave IL_012c - IL_004b: ldarg.0 - IL_004c: ldfld ""System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter Program.d__1.<>u__1"" - IL_0051: stloc.1 - IL_0052: ldarg.0 - IL_0053: ldflda ""System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter Program.d__1.<>u__1"" - IL_0058: initobj ""System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter"" - IL_005e: ldarg.0 - IL_005f: ldc.i4.m1 - IL_0060: dup - IL_0061: stloc.0 - IL_0062: stfld ""int Program.d__1.<>1__state"" - IL_0067: ldloca.s V_1 - IL_0069: call ""void System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter.GetResult()"" - IL_006e: ldarg.0 - IL_006f: ldflda ""T Program.d__1.item"" - IL_0074: call ""int Program.GetOffset(ref T)"" - IL_0079: call ""System.Threading.Tasks.Task Program.GetOffsetAsync(int)"" - IL_007e: callvirt ""System.Runtime.CompilerServices.TaskAwaiter System.Threading.Tasks.Task.GetAwaiter()"" - IL_0083: stloc.s V_5 - IL_0085: ldloca.s V_5 - IL_0087: call ""bool System.Runtime.CompilerServices.TaskAwaiter.IsCompleted.get"" - IL_008c: brtrue.s IL_00cc - IL_008e: ldarg.0 - IL_008f: ldc.i4.1 - IL_0090: dup - IL_0091: stloc.0 - IL_0092: stfld ""int Program.d__1.<>1__state"" - IL_0097: ldarg.0 - IL_0098: ldloc.s V_5 - IL_009a: stfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__2"" - IL_009f: ldarg.0 - IL_00a0: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" - IL_00a5: ldloca.s V_5 - IL_00a7: ldarg.0 - IL_00a8: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.AwaitUnsafeOnCompleted, Program.d__1>(ref System.Runtime.CompilerServices.TaskAwaiter, ref Program.d__1)"" - IL_00ad: leave.s IL_012c - IL_00af: ldarg.0 - IL_00b0: ldfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__2"" - IL_00b5: stloc.s V_5 - IL_00b7: ldarg.0 - IL_00b8: ldflda ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__2"" - IL_00bd: initobj ""System.Runtime.CompilerServices.TaskAwaiter"" - IL_00c3: ldarg.0 - IL_00c4: ldc.i4.m1 - IL_00c5: dup - IL_00c6: stloc.0 - IL_00c7: stfld ""int Program.d__1.<>1__state"" - IL_00cc: ldloca.s V_5 - IL_00ce: call ""int System.Runtime.CompilerServices.TaskAwaiter.GetResult()"" - IL_00d3: stloc.3 - IL_00d4: ldarg.0 - IL_00d5: ldflda ""T Program.d__1.item"" - IL_00da: ldloc.3 - IL_00db: constrained. ""T"" - IL_00e1: callvirt ""int IMoveable.this[int].get"" - IL_00e6: stloc.s V_4 - IL_00e8: ldarg.0 - IL_00e9: ldflda ""T Program.d__1.item"" - IL_00ee: ldloc.3 - IL_00ef: ldloc.s V_4 - IL_00f1: ldc.i4.1 - IL_00f2: add - IL_00f3: constrained. ""T"" - IL_00f9: callvirt ""void IMoveable.this[int].set"" - IL_00fe: leave.s IL_0119 + IL_0008: brfalse.s IL_0077 + IL_000a: ldarg.0 + IL_000b: ldarg.0 + IL_000c: ldfld ""T[] Program.d__1.item"" + IL_0011: stfld ""T[] Program.d__1.<>7__wrap1"" + IL_0016: ldarg.0 + IL_0017: call ""int Program.GetArrayIndex()"" + IL_001c: stfld ""int Program.d__1.<>7__wrap2"" + IL_0021: ldarg.0 + IL_0022: ldfld ""T[] Program.d__1.<>7__wrap1"" + IL_0027: ldarg.0 + IL_0028: ldfld ""int Program.d__1.<>7__wrap2"" + IL_002d: readonly. + IL_002f: ldelema ""T"" + IL_0034: pop + IL_0035: ldarg.0 + IL_0036: ldflda ""T[] Program.d__1.item"" + IL_003b: call ""int Program.GetOffset(ref T[])"" + IL_0040: call ""System.Threading.Tasks.Task Program.GetOffsetAsync(int)"" + IL_0045: callvirt ""System.Runtime.CompilerServices.TaskAwaiter System.Threading.Tasks.Task.GetAwaiter()"" + IL_004a: stloc.3 + IL_004b: ldloca.s V_3 + IL_004d: call ""bool System.Runtime.CompilerServices.TaskAwaiter.IsCompleted.get"" + IL_0052: brtrue.s IL_0093 + IL_0054: ldarg.0 + IL_0055: ldc.i4.0 + IL_0056: dup + IL_0057: stloc.0 + IL_0058: stfld ""int Program.d__1.<>1__state"" + IL_005d: ldarg.0 + IL_005e: ldloc.3 + IL_005f: stfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_0064: ldarg.0 + IL_0065: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_006a: ldloca.s V_3 + IL_006c: ldarg.0 + IL_006d: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.AwaitUnsafeOnCompleted, Program.d__1>(ref System.Runtime.CompilerServices.TaskAwaiter, ref Program.d__1)"" + IL_0072: leave IL_0112 + IL_0077: ldarg.0 + IL_0078: ldfld ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_007d: stloc.3 + IL_007e: ldarg.0 + IL_007f: ldflda ""System.Runtime.CompilerServices.TaskAwaiter Program.d__1.<>u__1"" + IL_0084: initobj ""System.Runtime.CompilerServices.TaskAwaiter"" + IL_008a: ldarg.0 + IL_008b: ldc.i4.m1 + IL_008c: dup + IL_008d: stloc.0 + IL_008e: stfld ""int Program.d__1.<>1__state"" + IL_0093: ldloca.s V_3 + IL_0095: call ""int System.Runtime.CompilerServices.TaskAwaiter.GetResult()"" + IL_009a: stloc.1 + IL_009b: ldarg.0 + IL_009c: ldfld ""T[] Program.d__1.<>7__wrap1"" + IL_00a1: ldarg.0 + IL_00a2: ldfld ""int Program.d__1.<>7__wrap2"" + IL_00a7: readonly. + IL_00a9: ldelema ""T"" + IL_00ae: ldloc.1 + IL_00af: constrained. ""T"" + IL_00b5: callvirt ""int IMoveable.this[int].get"" + IL_00ba: stloc.2 + IL_00bb: ldarg.0 + IL_00bc: ldfld ""T[] Program.d__1.<>7__wrap1"" + IL_00c1: ldarg.0 + IL_00c2: ldfld ""int Program.d__1.<>7__wrap2"" + IL_00c7: readonly. + IL_00c9: ldelema ""T"" + IL_00ce: ldloc.1 + IL_00cf: ldloc.2 + IL_00d0: ldc.i4.1 + IL_00d1: add + IL_00d2: constrained. ""T"" + IL_00d8: callvirt ""void IMoveable.this[int].set"" + IL_00dd: ldarg.0 + IL_00de: ldnull + IL_00df: stfld ""T[] Program.d__1.<>7__wrap1"" + IL_00e4: leave.s IL_00ff } catch System.Exception { - IL_0100: stloc.s V_6 - IL_0102: ldarg.0 - IL_0103: ldc.i4.s -2 - IL_0105: stfld ""int Program.d__1.<>1__state"" - IL_010a: ldarg.0 - IL_010b: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" - IL_0110: ldloc.s V_6 - IL_0112: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException(System.Exception)"" - IL_0117: leave.s IL_012c + IL_00e6: stloc.s V_4 + IL_00e8: ldarg.0 + IL_00e9: ldc.i4.s -2 + IL_00eb: stfld ""int Program.d__1.<>1__state"" + IL_00f0: ldarg.0 + IL_00f1: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_00f6: ldloc.s V_4 + IL_00f8: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException(System.Exception)"" + IL_00fd: leave.s IL_0112 } - IL_0119: ldarg.0 - IL_011a: ldc.i4.s -2 - IL_011c: stfld ""int Program.d__1.<>1__state"" - IL_0121: ldarg.0 - IL_0122: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" - IL_0127: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()"" - IL_012c: ret + IL_00ff: ldarg.0 + IL_0100: ldc.i4.s -2 + IL_0102: stfld ""int Program.d__1.<>1__state"" + IL_0107: ldarg.0 + IL_0108: ldflda ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder Program.d__1.<>t__builder"" + IL_010d: call ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()"" + IL_0112: ret } "); } diff --git a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenCallTests.vb b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenCallTests.vb index 8dc5a45f4890b..2da162522df15 100644 --- a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenCallTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenCallTests.vb @@ -99,6 +99,148 @@ End Class ]]>) End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Call_Class_InWith(asRValue As Boolean) + + Dim leftParen As String = "" + Dim rightParen As String = "" + + If asRValue Then + leftParen = "(" + rightParen = ")" + End If + + Dim comp = + + +Imports System + +Interface IMoveable + Sub GetName(x As Integer) +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Sub GetName(x As Integer) Implements IMoveable.GetName + Console.WriteLine("Position GetName for item '{0}'", Me.Name) + End Sub +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1) + + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + + Dim item3 = New Item With {.Name = "3"} + Call3(item3) + End Sub + + Private Shared Sub Call1(Of T As {Class, IMoveable})(item As T) + With <%= leftParen %>item<%= rightParen %> + call .GetName(GetOffset(item)) + End With + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(item As T) + With <%= leftParen %>item<%= rightParen %> + call .GetName(GetOffset(item)) + End With + End Sub + + Private Shared Sub Call3(item As Item) + With <%= leftParen %>item<%= rightParen %> + call .GetName(GetOffset(item)) + End With + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position GetName for item '1' +Position GetName for item '2' +Position GetName for item '3' +").VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.Call1(Of T)", + If(asRValue, + , + )) + + 'Wrong IL + verifier.VerifyIL("Program.Call2(Of T)", + If(asRValue, + , + )) + End Sub + Public Sub GenericTypeParameterAsReceiver_Call_Struct() @@ -1230,13 +1372,24 @@ Position GetName for item '-2' ]]>) End Sub - + + - Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Class() + Public Sub GenericTypeParameterAsReceiver_Call_Class_Async_01_ThroughArray(asRValue As Boolean) + + Dim leftParen As String = "" + Dim rightParen As String = "" + + If asRValue Then + leftParen = "(" + rightParen = ")" + End If + Dim comp = Imports System +Imports System.Threading.Tasks Interface IMoveable Sub GetName(x As Integer) @@ -1252,141 +1405,300 @@ Class Item End Sub End Class +Class Item2 + Inherits Item +End Class + Class Program Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} - Call1(item1) + Dim item1 = {New Item2 With {.Name = "1"}} + Call1(DirectCast(item1, Item())).Wait() - Dim item2 = New Item With {.Name = "2"} - Call2(item2) - End Sub + Dim item2 = {New Item2 With {.Name = "2"}} + Call2(DirectCast(item2, Item())).Wait() - Private Shared Sub Call1(Of T As {Class, IMoveable})(item As T) - item?.GetName(GetOffset(item)) + Dim item3 = {New Item2 With {.Name = "3"}} + Call3(DirectCast(item3, Item())).Wait() End Sub - Private Shared Sub Call2(Of T As {IMoveable})(item As T) - item?.GetName(GetOffset(item)) - End Sub + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T()) As Task + call <%= leftParen %>item(GetArrayIndex())<%= rightParen %>.GetName(await GetOffsetAsync(GetOffset(item))) + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T()) As Task + call <%= leftParen %>item(GetArrayIndex())<%= rightParen %>.GetName(await GetOffsetAsync(GetOffset(item))) + End Function + + Private Shared Async Function Call3(item As Item()) As Task + call <%= leftParen %>item(GetArrayIndex())<%= rightParen %>.GetName(await GetOffsetAsync(GetOffset(item))) + End Function Shared value as Integer - Shared Function GetOffset(Of T)(ByRef item As T) As Integer + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + item(0) = DirectCast(DirectCast(New Item2 With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function + + Shared Function GetArrayIndex() As Integer Return 0 End Function End Class - ' Wrong output on some frameworks - ' Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= - '" - 'Position GetName for item '1' - 'Position GetName for item '2' - '").VerifyDiagnostics() - Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe).VerifyDiagnostics() + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position GetName for item '-1' +Position GetName for item '-2' +Position GetName for item '3' +").VerifyDiagnostics() - verifier.VerifyIL("Program.Call1(Of T)", + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) - 'Wrong IL - verifier.VerifyIL("Program.Call2(Of T)", + verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", ) - End Sub - - - - Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Struct() - Dim comp = - - -Imports System - -Interface IMoveable - Sub GetName(x As Integer) -End Interface - -Structure Item - Implements IMoveable - - Public Property Name As String - - Public Sub GetName(x As Integer) Implements IMoveable.GetName - Console.WriteLine("Position GetName for item '{0}'", Me.Name) - End Sub -End Structure - -Class Program - Shared Sub Main() - Dim item2 = New Item With {.Name = "2"} - Call2(item2) - End Sub - - Private Shared Sub Call2(Of T As {IMoveable})(item As T) - item?.GetName(GetOffset(item)) - End Sub + IL_0001: ldfld "Program.VB$StateMachine_3_Call2(Of SM$T).$State As Integer" + IL_0006: stloc.0 + .try + { + IL_0007: ldloc.0 + IL_0008: brfalse.s IL_0077 + IL_000a: ldarg.0 + IL_000b: ldarg.0 + IL_000c: ldfld "Program.VB$StateMachine_3_Call2(Of SM$T).$VB$Local_item As SM$T()" + IL_0011: stfld "Program.VB$StateMachine_3_Call2(Of SM$T).$U1 As SM$T()" + IL_0016: ldarg.0 + IL_0017: call "Function Program.GetArrayIndex() As Integer" + IL_001c: stfld "Program.VB$StateMachine_3_Call2(Of SM$T).$U2 As Integer" + IL_0021: ldarg.0 + IL_0022: ldfld "Program.VB$StateMachine_3_Call2(Of SM$T).$U1 As SM$T()" + IL_0027: ldarg.0 + IL_0028: ldfld "Program.VB$StateMachine_3_Call2(Of SM$T).$U2 As Integer" + IL_002d: readonly. + IL_002f: ldelema "SM$T" + IL_0034: pop + IL_0035: ldarg.0 + IL_0036: ldflda "Program.VB$StateMachine_3_Call2(Of SM$T).$VB$Local_item As SM$T()" + IL_003b: call "Function Program.GetOffset(Of SM$T)(ByRef SM$T()) As Integer" + IL_0040: call "Function Program.GetOffsetAsync(Integer) As System.Threading.Tasks.Task(Of Integer)" + IL_0045: callvirt "Function System.Threading.Tasks.Task(Of Integer).GetAwaiter() As System.Runtime.CompilerServices.TaskAwaiter(Of Integer)" + IL_004a: stloc.1 + IL_004b: ldloca.s V_1 + IL_004d: call "Function System.Runtime.CompilerServices.TaskAwaiter(Of Integer).get_IsCompleted() As Boolean" + IL_0052: brtrue.s IL_0093 + IL_0054: ldarg.0 + IL_0055: ldc.i4.0 + IL_0056: dup + IL_0057: stloc.0 + IL_0058: stfld "Program.VB$StateMachine_3_Call2(Of SM$T).$State As Integer" + IL_005d: ldarg.0 + IL_005e: ldloc.1 + IL_005f: stfld "Program.VB$StateMachine_3_Call2(Of SM$T).$A0 As System.Runtime.CompilerServices.TaskAwaiter(Of Integer)" + IL_0064: ldarg.0 + IL_0065: ldflda "Program.VB$StateMachine_3_Call2(Of SM$T).$Builder As System.Runtime.CompilerServices.AsyncTaskMethodBuilder" + IL_006a: ldloca.s V_1 + IL_006c: ldarg.0 + IL_006d: call "Sub System.Runtime.CompilerServices.AsyncTaskMethodBuilder.AwaitUnsafeOnCompleted(Of System.Runtime.CompilerServices.TaskAwaiter(Of Integer), Program.VB$StateMachine_3_Call2(Of SM$T))(ByRef System.Runtime.CompilerServices.TaskAwaiter(Of Integer), ByRef Program.VB$StateMachine_3_Call2(Of SM$T))" + IL_0072: leave IL_0100 + IL_0077: ldarg.0 + IL_0078: ldc.i4.m1 + IL_0079: dup + IL_007a: stloc.0 + IL_007b: stfld "Program.VB$StateMachine_3_Call2(Of SM$T).$State As Integer" + IL_0080: ldarg.0 + IL_0081: ldfld "Program.VB$StateMachine_3_Call2(Of SM$T).$A0 As System.Runtime.CompilerServices.TaskAwaiter(Of Integer)" + IL_0086: stloc.1 + IL_0087: ldarg.0 + IL_0088: ldflda "Program.VB$StateMachine_3_Call2(Of SM$T).$A0 As System.Runtime.CompilerServices.TaskAwaiter(Of Integer)" + IL_008d: initobj "System.Runtime.CompilerServices.TaskAwaiter(Of Integer)" + IL_0093: ldarg.0 + IL_0094: ldfld "Program.VB$StateMachine_3_Call2(Of SM$T).$U1 As SM$T()" + IL_0099: ldarg.0 + IL_009a: ldfld "Program.VB$StateMachine_3_Call2(Of SM$T).$U2 As Integer" + IL_009f: readonly. + IL_00a1: ldelema "SM$T" + IL_00a6: ldloca.s V_1 + IL_00a8: call "Function System.Runtime.CompilerServices.TaskAwaiter(Of Integer).GetResult() As Integer" + IL_00ad: ldloca.s V_1 + IL_00af: initobj "System.Runtime.CompilerServices.TaskAwaiter(Of Integer)" + IL_00b5: constrained. "SM$T" + IL_00bb: callvirt "Sub IMoveable.GetName(Integer)" + IL_00c0: ldarg.0 + IL_00c1: ldnull + IL_00c2: stfld "Program.VB$StateMachine_3_Call2(Of SM$T).$U1 As SM$T()" + IL_00c7: leave.s IL_00eb + } + catch System.Exception + { + IL_00c9: dup + IL_00ca: call "Sub Microsoft.VisualBasic.CompilerServices.ProjectData.SetProjectError(System.Exception)" + IL_00cf: stloc.2 + IL_00d0: ldarg.0 + IL_00d1: ldc.i4.s -2 + IL_00d3: stfld "Program.VB$StateMachine_3_Call2(Of SM$T).$State As Integer" + IL_00d8: ldarg.0 + IL_00d9: ldflda "Program.VB$StateMachine_3_Call2(Of SM$T).$Builder As System.Runtime.CompilerServices.AsyncTaskMethodBuilder" + IL_00de: ldloc.2 + IL_00df: call "Sub System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetException(System.Exception)" + IL_00e4: call "Sub Microsoft.VisualBasic.CompilerServices.ProjectData.ClearProjectError()" + IL_00e9: leave.s IL_0100 + } + IL_00eb: ldarg.0 + IL_00ec: ldc.i4.s -2 + IL_00ee: dup + IL_00ef: stloc.0 + IL_00f0: stfld "Program.VB$StateMachine_3_Call2(Of SM$T).$State As Integer" + IL_00f5: ldarg.0 + IL_00f6: ldflda "Program.VB$StateMachine_3_Call2(Of SM$T).$Builder As System.Runtime.CompilerServices.AsyncTaskMethodBuilder" + IL_00fb: call "Sub System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()" + IL_0100: ret +} +]]>) + End Sub - Shared value as Integer + + + + Public Sub GenericTypeParameterAsReceiver_Call_Struct_Async_01_ThroughArray(asRValue As Boolean) - Shared Function GetOffset(Of T)(ByRef item As T) As Integer - value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) - Return 0 - End Function -End Class - - + Dim leftParen As String = "" + Dim rightParen As String = "" - Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= -" -Position GetName for item '-1' -").VerifyDiagnostics() - End Sub + If asRValue Then + leftParen = "(" + rightParen = ")" + End If - - - Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Class_Ref() Dim comp = Imports System +Imports System.Threading.Tasks Interface IMoveable Sub GetName(x As Integer) End Interface -Class Item +Structure Item Implements IMoveable Public Property Name As String @@ -1394,30 +1706,45 @@ Class Item Public Sub GetName(x As Integer) Implements IMoveable.GetName Console.WriteLine("Position GetName for item '{0}'", Me.Name) End Sub -End Class +End Structure Class Program Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} - Call1(item1) + Dim item1 = {New Item With {.Name = "1"}} + Call1(item1).Wait() - Dim item2 = New Item With {.Name = "2"} - Call2(item2) - End Sub + Dim item2 = {New Item With {.Name = "2"}} + Call2(item2).Wait() - Private Shared Sub Call1(Of T As {Class, IMoveable})(ByRef item As T) - item?.GetName(GetOffset(item)) + Dim item3 = {New Item With {.Name = "3"}} + Call3(item3).Wait() End Sub - Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) - item?.GetName(GetOffset(item)) - End Sub + Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T()) As Task + call <%= leftParen %>item(GetArrayIndex())<%= rightParen %>.GetName(await GetOffsetAsync(GetOffset(item))) + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T()) As Task + call <%= leftParen %>item(GetArrayIndex())<%= rightParen %>.GetName(await GetOffsetAsync(GetOffset(item))) + End Function + + Private Shared Async Function Call3(item As Item()) As Task + call <%= leftParen %>item(GetArrayIndex())<%= rightParen %>.GetName(await GetOffsetAsync(GetOffset(item))) + End Function Shared value as Integer - Shared Function GetOffset(Of T)(ByRef item As T) As Integer + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + item(0) = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function + + Shared Function GetArrayIndex() As Integer Return 0 End Function End Class @@ -1426,71 +1753,143 @@ End Class Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " -Position GetName for item '1' -Position GetName for item '2' +Position GetName for item '-1' +Position GetName for item '-2' +Position GetName for item '-3' ").VerifyDiagnostics() - verifier.VerifyIL("Program.Call1(Of T)", - ) - - verifier.VerifyIL("Program.Call2(Of T)", + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) End Sub - + + - Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Struct_Ref() + Public Sub GenericTypeParameterAsReceiver_Call_Class_Async_01_ThroughArray_InWith(asRValue As Boolean) + + Dim leftParen As String = "" + Dim rightParen As String = "" + + If asRValue Then + leftParen = "(" + rightParen = ")" + End If + Dim comp = Imports System +Imports System.Threading.Tasks Interface IMoveable Sub GetName(x As Integer) End Interface -Structure Item +Class Item Implements IMoveable Public Property Name As String @@ -1498,49 +1897,514 @@ Structure Item Public Sub GetName(x As Integer) Implements IMoveable.GetName Console.WriteLine("Position GetName for item '{0}'", Me.Name) End Sub -End Structure +End Class + +Class Item2 + Inherits Item +End Class Class Program Shared Sub Main() - Dim item2 = New Item With {.Name = "2"} - Call2(item2) - End Sub + Dim item1 = {New Item2 With {.Name = "1"}} + Call1(DirectCast(item1, Item())).Wait() - Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) - item?.GetName(GetOffset(item)) + Dim item2 = {New Item2 With {.Name = "2"}} + Call2(DirectCast(item2, Item())).Wait() + + Dim item3 = {New Item2 With {.Name = "3"}} + Call3(DirectCast(item3, Item())).Wait() End Sub + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T()) As Task + With <%= leftParen %>item(GetArrayIndex())<%= rightParen %> + call .GetName(await GetOffsetAsync(GetOffset(item))) + End With + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T()) As Task + With <%= leftParen %>item(GetArrayIndex())<%= rightParen %> + call .GetName(await GetOffsetAsync(GetOffset(item))) + End With + End Function + + Private Shared Async Function Call3(item As Item()) As Task + With <%= leftParen %>item(GetArrayIndex())<%= rightParen %> + call .GetName(await GetOffsetAsync(GetOffset(item))) + End With + End Function + Shared value as Integer - Shared Function GetOffset(Of T)(ByRef item As T) As Integer + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + item(0) = DirectCast(DirectCast(New Item2 With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function + + Shared Function GetArrayIndex() As Integer Return 0 End Function End Class + ' Wrong output for asRValue = False case Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +If(asRValue, +" +Position GetName for item '1' +Position GetName for item '2' +Position GetName for item '3' +", " Position GetName for item '-1' -").VerifyDiagnostics() - End Sub - - - - Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Class_Async_01() - Dim comp = - - -Imports System -Imports System.Threading.Tasks +Position GetName for item '-2' +Position GetName for item '3' +")).VerifyDiagnostics() -Interface IMoveable - Sub GetName(x As Integer) + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", +If(asRValue, + , + )) + + verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", +If(asRValue, + , + )) + End Sub + + + + + Public Sub GenericTypeParameterAsReceiver_Call_Struct_Async_01_ThroughArray_InWith(asRValue As Boolean) + + Dim leftParen As String = "" + Dim rightParen As String = "" + + If asRValue Then + leftParen = "(" + rightParen = ")" + End If + + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Sub GetName(x As Integer) End Interface -Class Item +Structure Item Implements IMoveable Public Property Name As String @@ -1548,57 +2412,78 @@ Class Item Public Sub GetName(x As Integer) Implements IMoveable.GetName Console.WriteLine("Position GetName for item '{0}'", Me.Name) End Sub -End Class +End Structure Class Program Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} + Dim item1 = {New Item With {.Name = "1"}} Call1(item1).Wait() - Dim item2 = New Item With {.Name = "2"} + Dim item2 = {New Item With {.Name = "2"}} Call2(item2).Wait() + + Dim item3 = {New Item With {.Name = "3"}} + Call3(item3).Wait() End Sub - Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task - item?.GetName(await GetOffsetAsync(GetOffset(item))) + Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T()) As Task + With <%= leftParen %>item(GetArrayIndex())<%= rightParen %> + call .GetName(await GetOffsetAsync(GetOffset(item))) + End With End Function - Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - item?.GetName(await GetOffsetAsync(GetOffset(item))) + Private Shared Async Function Call2(Of T As {IMoveable})(item As T()) As Task + With <%= leftParen %>item(GetArrayIndex())<%= rightParen %> + call .GetName(await GetOffsetAsync(GetOffset(item))) + End With + End Function + + Private Shared Async Function Call3(item As Item()) As Task + With <%= leftParen %>item(GetArrayIndex())<%= rightParen %> + call .GetName(await GetOffsetAsync(GetOffset(item))) + End With End Function Shared value as Integer - Shared Function GetOffset(Of T)(ByRef item As T) As Integer + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + item(0) = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) Return 0 End Function Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) Return Task.FromResult(i) End Function + + Shared Function GetArrayIndex() As Integer + Return 0 + End Function End Class - ' Wrong output Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +If(asRValue, +" +Position GetName for item '1' +Position GetName for item '2' +Position GetName for item '3' +", " Position GetName for item '-1' Position GetName for item '-2' -", verify:=Verification.Skipped).VerifyDiagnostics() +Position GetName for item '-3' +")).VerifyDiagnostics() - 'Wrong IL - 'PEVerify failed - '[ : Program+VB$StateMachine_2_Call1`1[SM$T]::MoveNext][mdToken=0x600000c][offset 0x00000019][found (unboxed) 'SM$T'] Non-compatible types on the stack. verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", +If(asRValue, ) - - 'Wrong IL - verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", +]]>, )) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Class() + Dim comp = + + +Imports System + +Interface IMoveable + Sub GetName(x As Integer) +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Sub GetName(x As Integer) Implements IMoveable.GetName + Console.WriteLine("Position GetName for item '{0}'", Me.Name) + End Sub +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1) + + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Class, IMoveable})(item As T) + item?.GetName(GetOffset(item)) + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(item As T) + item?.GetName(GetOffset(item)) + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + ' Wrong output on some frameworks + ' Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= + '" + 'Position GetName for item '1' + 'Position GetName for item '2' + '").VerifyDiagnostics() + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe).VerifyDiagnostics() + + verifier.VerifyIL("Program.Call1(Of T)", + ) + + 'Wrong IL + verifier.VerifyIL("Program.Call2(Of T)", + ) End Sub - Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Struct_Async_01() + Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Struct() Dim comp = Imports System -Imports System.Threading.Tasks Interface IMoveable Sub GetName(x As Integer) @@ -1809,12 +2804,12 @@ End Structure Class Program Shared Sub Main() Dim item2 = New Item With {.Name = "2"} - Call2(item2).Wait() + Call2(item2) End Sub - Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - item?.GetName(await GetOffsetAsync(GetOffset(item))) - End Function + Private Shared Sub Call2(Of T As {IMoveable})(item As T) + item?.GetName(GetOffset(item)) + End Sub Shared value as Integer @@ -1823,10 +2818,6 @@ Class Program item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) Return 0 End Function - - Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) - Return Task.FromResult(i) - End Function End Class @@ -1839,12 +2830,11 @@ Position GetName for item '-1' - Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Class_Async_02() + Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Class_Ref() Dim comp = Imports System -Imports System.Threading.Tasks Interface IMoveable Sub GetName(x As Integer) @@ -1863,21 +2853,19 @@ End Class Class Program Shared Sub Main() Dim item1 = New Item With {.Name = "1"} - Call1(item1).Wait() + Call1(item1) Dim item2 = New Item With {.Name = "2"} - Call2(item2).Wait() + Call2(item2) End Sub - Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task - await Task.Yield() - item?.GetName(await GetOffsetAsync(GetOffset(item))) - End Function + Private Shared Sub Call1(Of T As {Class, IMoveable})(ByRef item As T) + item?.GetName(GetOffset(item)) + End Sub - Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - await Task.Yield() - item?.GetName(await GetOffsetAsync(GetOffset(item))) - End Function + Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) + item?.GetName(GetOffset(item)) + End Sub Shared value as Integer @@ -1886,302 +2874,4236 @@ Class Program item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) Return 0 End Function - - Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) - Return Task.FromResult(i) - End Function End Class - ' Wrong output Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " -Position GetName for item '-1' -Position GetName for item '-2' -", verify:=Verification.Skipped).VerifyDiagnostics() +Position GetName for item '1' +Position GetName for item '2' +").VerifyDiagnostics() - 'Wrong IL - 'PEVerify failed - '[ : Program+VB$StateMachine_2_Call1`1[SM$T]::MoveNext][mdToken=0x600000c][offset 0x00000085][found (unboxed) 'SM$T'] Non-compatible types on the stack. - verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + verifier.VerifyIL("Program.Call1(Of T)", ) + + verifier.VerifyIL("Program.Call2(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Struct_Ref() + Dim comp = + + +Imports System + +Interface IMoveable + Sub GetName(x As Integer) +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Sub GetName(x As Integer) Implements IMoveable.GetName + Console.WriteLine("Position GetName for item '{0}'", Me.Name) + End Sub +End Structure + +Class Program + Shared Sub Main() + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) + item?.GetName(GetOffset(item)) + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position GetName for item '-1' +").VerifyDiagnostics() + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Class_Async_01() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Sub GetName(x As Integer) +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Sub GetName(x As Integer) Implements IMoveable.GetName + Console.WriteLine("Position GetName for item '{0}'", Me.Name) + End Sub +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1).Wait() + + Dim item2 = New Item With {.Name = "2"} + Call2(item2).Wait() + End Sub + + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task + item?.GetName(await GetOffsetAsync(GetOffset(item))) + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + item?.GetName(await GetOffsetAsync(GetOffset(item))) + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function +End Class + + + + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position GetName for item '-1' +Position GetName for item '-2' +", verify:=Verification.Skipped).VerifyDiagnostics() + + 'Wrong IL + 'PEVerify failed + '[ : Program+VB$StateMachine_2_Call1`1[SM$T]::MoveNext][mdToken=0x600000c][offset 0x00000019][found (unboxed) 'SM$T'] Non-compatible types on the stack. + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + ) + + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Struct_Async_01() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Sub GetName(x As Integer) +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Sub GetName(x As Integer) Implements IMoveable.GetName + Console.WriteLine("Position GetName for item '{0}'", Me.Name) + End Sub +End Structure + +Class Program + Shared Sub Main() + Dim item2 = New Item With {.Name = "2"} + Call2(item2).Wait() + End Sub + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + item?.GetName(await GetOffsetAsync(GetOffset(item))) + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position GetName for item '-1' +").VerifyDiagnostics() + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Class_Async_02() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Sub GetName(x As Integer) +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Sub GetName(x As Integer) Implements IMoveable.GetName + Console.WriteLine("Position GetName for item '{0}'", Me.Name) + End Sub +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1).Wait() + + Dim item2 = New Item With {.Name = "2"} + Call2(item2).Wait() + End Sub + + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task + await Task.Yield() + item?.GetName(await GetOffsetAsync(GetOffset(item))) + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + await Task.Yield() + item?.GetName(await GetOffsetAsync(GetOffset(item))) + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function +End Class + + + + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position GetName for item '-1' +Position GetName for item '-2' +", verify:=Verification.Skipped).VerifyDiagnostics() + + 'Wrong IL + 'PEVerify failed + '[ : Program+VB$StateMachine_2_Call1`1[SM$T]::MoveNext][mdToken=0x600000c][offset 0x00000085][found (unboxed) 'SM$T'] Non-compatible types on the stack. + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + ) + + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Struct_Async_02() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Sub GetName(x As Integer) +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Sub GetName(x As Integer) Implements IMoveable.GetName + Console.WriteLine("Position GetName for item '{0}'", Me.Name) + End Sub +End Structure + +Class Program + Shared Sub Main() + Dim item2 = New Item With {.Name = "2"} + Call2(item2).Wait() + End Sub + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + await Task.Yield() + item?.GetName(await GetOffsetAsync(GetOffset(item))) + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position GetName for item '-1' +").VerifyDiagnostics() + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Class() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1) + + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Class, IMoveable})(item As T) + item.Position += GetOffset(item) + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(item As T) + item.Position += GetOffset(item) + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + ' Wrong output on some frameworks + ' Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= + '" + 'Position get for item '1' + 'Position set for item '1' + 'Position get for item '2' + 'Position set for item '2' + '").VerifyDiagnostics() + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe).VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.Call1(Of T)", + ) + + 'Wrong IL + verifier.VerifyIL("Program.Call2(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Struct() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position As Integer +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Property Position As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Structure + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1) + + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Structure, IMoveable})(item As T) + item.Position += GetOffset(item) + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(item As T) + item.Position += GetOffset(item) + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '1' +Position set for item '-1' +Position get for item '2' +Position set for item '-2' +").VerifyDiagnostics() + + verifier.VerifyIL("Program.Call1(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Class_Ref() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1) + + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Class, IMoveable})(ByRef item As T) + item.Position += GetOffset(item) + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) + item.Position += GetOffset(item) + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + ' Wrong output on some frameworks + ' Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= + '" + 'Position get for item '1' + 'Position set for item '1' + 'Position get for item '2' + 'Position set for item '2' + '").VerifyDiagnostics() + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe).VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.Call1(Of T)", + ) + + 'Wrong IL + verifier.VerifyIL("Program.Call2(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Struct_Ref() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position As Integer +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Property Position As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Structure + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1) + + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Structure, IMoveable})(ByRef item As T) + item.Position += GetOffset(item) + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) + item.Position += GetOffset(item) + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '1' +Position set for item '-1' +Position get for item '2' +Position set for item '-2' +").VerifyDiagnostics() + + verifier.VerifyIL("Program.Call1(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Class_Async_01() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Property Position As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1).Wait() + + Dim item2 = New Item With {.Name = "2"} + Call2(item2).Wait() + End Sub + + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task + item.Position += await GetOffsetAsync(GetOffset(item)) + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + item.Position += await GetOffsetAsync(GetOffset(item)) + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function +End Class + + + + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '1' +Position set for item '-1' +Position get for item '2' +Position set for item '-2' +").VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + ) + + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Struct_Async_01() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Property Position As Integer +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Property Position As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Structure + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1).Wait() + + Dim item2 = New Item With {.Name = "2"} + Call2(item2).Wait() + End Sub + + Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T) As Task + item.Position += await GetOffsetAsync(GetOffset(item)) + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + item.Position += await GetOffsetAsync(GetOffset(item)) + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '1' +Position set for item '-1' +Position get for item '2' +Position set for item '-2' +").VerifyDiagnostics() + + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Class_Async_02() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Property Position As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1).Wait() + + Dim item2 = New Item With {.Name = "2"} + Call2(item2).Wait() + End Sub + + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task + await Task.Yield() + item.Position += await GetOffsetAsync(GetOffset(item)) + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + await Task.Yield() + item.Position += await GetOffsetAsync(GetOffset(item)) + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function +End Class + + + + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '1' +Position set for item '-1' +Position get for item '2' +Position set for item '-2' +").VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + ) + + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Struct_Async_02() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Property Position As Integer +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Property Position As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Structure + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1).Wait() + + Dim item2 = New Item With {.Name = "2"} + Call2(item2).Wait() + End Sub + + Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T) As Task + await Task.Yield() + item.Position += await GetOffsetAsync(GetOffset(item)) + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + await Task.Yield() + item.Position += await GetOffsetAsync(GetOffset(item)) + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '1' +Position set for item '-1' +Position get for item '2' +Position set for item '-2' +").VerifyDiagnostics() + + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1) + + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Class, IMoveable})(item As T) + item.Position(GetOffset(item)) += 1 + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(item As T) + item.Position(GetOffset(item)) += 1 + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.Call1(Of T)", + ) + + 'Wrong IL + verifier.VerifyIL("Program.Call2(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Structure + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1) + + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Structure, IMoveable})(item As T) + item.Position(GetOffset(item)) += 1 + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(item As T) + item.Position(GetOffset(item)) += 1 + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() + + verifier.VerifyIL("Program.Call1(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index_Ref() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1) + + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Class, IMoveable})(ByRef item As T) + item.Position(GetOffset(item)) += 1 + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) + item.Position(GetOffset(item)) += 1 + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.Call1(Of T)", + ) + + 'Wrong IL + verifier.VerifyIL("Program.Call2(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index_Ref() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Structure + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1) + + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Structure, IMoveable})(ByRef item As T) + item.Position(GetOffset(item)) += 1 + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) + item.Position(GetOffset(item)) += 1 + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() + + verifier.VerifyIL("Program.Call1(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index_Async_01() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1).Wait() + + Dim item2 = New Item With {.Name = "2"} + Call2(item2).Wait() + End Sub + + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task + item.Position(await GetOffsetAsync(GetOffset(item))) += 1 + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + item.Position(await GetOffsetAsync(GetOffset(item))) += 1 + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function +End Class + + + + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + ) + + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index_Async_01() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Structure + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1).Wait() + + Dim item2 = New Item With {.Name = "2"} + Call2(item2).Wait() + End Sub + + Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T) As Task + item.Position(await GetOffsetAsync(GetOffset(item))) += 1 + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + item.Position(await GetOffsetAsync(GetOffset(item))) += 1 + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() + + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index_Async_02() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Property Position(x as Integer) As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x as Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1).Wait() + + Dim item2 = New Item With {.Name = "2"} + Call2(item2).Wait() + End Sub + + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task + await Task.Yield() + item.Position(await GetOffsetAsync(GetOffset(item))) += 1 + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + await Task.Yield() + item.Position(await GetOffsetAsync(GetOffset(item))) += 1 + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function +End Class + + + + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + ) + + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index_Async_02() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Property Position(x as Integer) As Integer +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x as Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Structure + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1).Wait() + + Dim item2 = New Item With {.Name = "2"} + Call2(item2).Wait() + End Sub + + Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T) As Task + await Task.Yield() + item.Position(await GetOffsetAsync(GetOffset(item))) += 1 + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + await Task.Yield() + item.Position(await GetOffsetAsync(GetOffset(item))) += 1 + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() + + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Value() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1) + + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Class, IMoveable})(item As T) + item.Position(1) += GetOffset(item) + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(item As T) + item.Position(1) += GetOffset(item) + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + ' Wrong output on some frameworks + ' Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= + '" + 'Position get for item '1' + 'Position set for item '1' + 'Position get for item '2' + 'Position set for item '2' + '").VerifyDiagnostics() + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe).VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.Call1(Of T)", + ) + + 'Wrong IL + verifier.VerifyIL("Program.Call2(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Value() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Structure + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1) + + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Structure, IMoveable})(item As T) + item.Position(1) += GetOffset(item) + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(item As T) + item.Position(1) += GetOffset(item) + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '1' +Position set for item '-1' +Position get for item '2' +Position set for item '-2' +").VerifyDiagnostics() + + verifier.VerifyIL("Program.Call1(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Value_Ref() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1) + + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Class, IMoveable})(ByRef item As T) + item.Position(1) += GetOffset(item) + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) + item.Position(1) += GetOffset(item) + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + 'Wrong output on some frameworks + ' Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= + '" + 'Position get for item '1' + 'Position set for item '1' + 'Position get for item '2' + 'Position set for item '2' + '").VerifyDiagnostics() + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe).VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.Call1(Of T)", + ) + + 'Wrong IL + verifier.VerifyIL("Program.Call2(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Value_Ref() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Structure + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1) + + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Structure, IMoveable})(ByRef item As T) + item.Position(1) += GetOffset(item) + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) + item.Position(1) += GetOffset(item) + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '1' +Position set for item '-1' +Position get for item '2' +Position set for item '-2' +").VerifyDiagnostics() + + verifier.VerifyIL("Program.Call1(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Value_Async_01() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1).Wait() + + Dim item2 = New Item With {.Name = "2"} + Call2(item2).Wait() + End Sub + + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task + item.Position(1) += await GetOffsetAsync(GetOffset(item)) + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + item.Position(1) += await GetOffsetAsync(GetOffset(item)) + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function +End Class + + + + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '1' +Position set for item '-1' +Position get for item '2' +Position set for item '-2' +").VerifyDiagnostics() 'Wrong IL - verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) + + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", + ) End Sub - Public Sub GenericTypeParameterAsReceiver_Call_Conditional_Struct_Async_02() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Value_Async_01() Dim comp = @@ -2189,7 +7111,7 @@ Imports System Imports System.Threading.Tasks Interface IMoveable - Sub GetName(x As Integer) + Property Position(x As Integer) As Integer End Interface Structure Item @@ -2197,20 +7119,32 @@ Structure Item Public Property Name As String - Public Sub GetName(x As Integer) Implements IMoveable.GetName - Console.WriteLine("Position GetName for item '{0}'", Me.Name) - End Sub + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property End Structure Class Program Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1).Wait() + Dim item2 = New Item With {.Name = "2"} Call2(item2).Wait() End Sub + Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T) As Task + item.Position(1) += await GetOffsetAsync(GetOffset(item)) + End Function + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - await Task.Yield() - item?.GetName(await GetOffsetAsync(GetOffset(item))) + item.Position(1) += await GetOffsetAsync(GetOffset(item)) End Function Shared value as Integer @@ -2230,20 +7164,120 @@ End Class Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " -Position GetName for item '-1' +Position get for item '1' +Position set for item '-1' +Position get for item '2' +Position set for item '-2' ").VerifyDiagnostics() + + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Class() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_IndexAndValue() Dim comp = Imports System Interface IMoveable - Property Position As Integer + Property Position(x As Integer) As Integer End Interface Class Item @@ -2251,7 +7285,7 @@ Class Item Public Property Name As String - Public Property Position As Integer Implements IMoveable.Position + Public Property Position(x As Integer) As Integer Implements IMoveable.Position Get Console.WriteLine("Position get for item '{0}'", Me.Name) Return 0 @@ -2272,11 +7306,11 @@ Class Program End Sub Private Shared Sub Call1(Of T As {Class, IMoveable})(item As T) - item.Position += GetOffset(item) + item.Position(GetOffset(item)) += GetOffset(item) End Sub Private Shared Sub Call2(Of T As {IMoveable})(item As T) - item.Position += GetOffset(item) + item.Position(GetOffset(item)) += GetOffset(item) End Sub Shared value as Integer @@ -2290,13 +7324,13 @@ End Class - ' Wrong output on some frameworks + ' Wrong output and differs, but still wrong, on some frameworks ' Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= '" - 'Position get for item '1' - 'Position set for item '1' - 'Position get for item '2' - 'Position set for item '2' + 'Position get for item '-1' + 'Position set for item '-1' + 'Position get for item '-3' + 'Position set for item '-3' '").VerifyDiagnostics() Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe).VerifyDiagnostics() @@ -2304,18 +7338,24 @@ End Class verifier.VerifyIL("Program.Call1(Of T)", ) @@ -2323,32 +7363,38 @@ End Class verifier.VerifyIL("Program.Call2(Of T)", ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Struct() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_IndexAndValue() Dim comp = Imports System Interface IMoveable - Property Position As Integer + Property Position(x As Integer) As Integer End Interface Structure Item @@ -2356,7 +7402,7 @@ Structure Item Public Property Name As String - Public Property Position As Integer Implements IMoveable.Position + Public Property Position(x As Integer) As Integer Implements IMoveable.Position Get Console.WriteLine("Position get for item '{0}'", Me.Name) Return 0 @@ -2377,11 +7423,11 @@ Class Program End Sub Private Shared Sub Call1(Of T As {Structure, IMoveable})(item As T) - item.Position += GetOffset(item) + item.Position(GetOffset(item)) += GetOffset(item) End Sub Private Shared Sub Call2(Of T As {IMoveable})(item As T) - item.Position += GetOffset(item) + item.Position(GetOffset(item)) += GetOffset(item) End Sub Shared value as Integer @@ -2397,41 +7443,47 @@ End Class Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " -Position get for item '1' -Position set for item '-1' -Position get for item '2' +Position get for item '-1' Position set for item '-2' +Position get for item '-3' +Position set for item '-4' ").VerifyDiagnostics() verifier.VerifyIL("Program.Call1(Of T)", ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Class_Ref() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_IndexAndValue_Ref() Dim comp = Imports System Interface IMoveable - Property Position As Integer + Property Position(x As Integer) As Integer End Interface Class Item @@ -2439,7 +7491,7 @@ Class Item Public Property Name As String - Public Property Position As Integer Implements IMoveable.Position + Public Property Position(x As Integer) As Integer Implements IMoveable.Position Get Console.WriteLine("Position get for item '{0}'", Me.Name) Return 0 @@ -2460,11 +7512,11 @@ Class Program End Sub Private Shared Sub Call1(Of T As {Class, IMoveable})(ByRef item As T) - item.Position += GetOffset(item) + item.Position(GetOffset(item)) += GetOffset(item) End Sub Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) - item.Position += GetOffset(item) + item.Position(GetOffset(item)) += GetOffset(item) End Sub Shared value as Integer @@ -2478,13 +7530,13 @@ End Class - ' Wrong output on some frameworks + ' Wrong output and framework dependent ' Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= '" - 'Position get for item '1' - 'Position set for item '1' - 'Position get for item '2' - 'Position set for item '2' + 'Position get for item '-1' + 'Position set for item '-1' + 'Position get for item '-3' + 'Position set for item '-3' '").VerifyDiagnostics() Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe).VerifyDiagnostics() @@ -2492,18 +7544,24 @@ End Class verifier.VerifyIL("Program.Call1(Of T)", ) @@ -2511,32 +7569,38 @@ End Class verifier.VerifyIL("Program.Call2(Of T)", ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Struct_Ref() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_IndexAndValue_Ref() Dim comp = Imports System Interface IMoveable - Property Position As Integer + Property Position(x As Integer) As Integer End Interface Structure Item @@ -2544,7 +7608,7 @@ Structure Item Public Property Name As String - Public Property Position As Integer Implements IMoveable.Position + Public Property Position(x As Integer) As Integer Implements IMoveable.Position Get Console.WriteLine("Position get for item '{0}'", Me.Name) Return 0 @@ -2565,11 +7629,11 @@ Class Program End Sub Private Shared Sub Call1(Of T As {Structure, IMoveable})(ByRef item As T) - item.Position += GetOffset(item) + item.Position(GetOffset(item)) += GetOffset(item) End Sub Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) - item.Position += GetOffset(item) + item.Position(GetOffset(item)) += GetOffset(item) End Sub Shared value as Integer @@ -2585,34 +7649,40 @@ End Class Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " -Position get for item '1' -Position set for item '-1' -Position get for item '2' +Position get for item '-1' Position set for item '-2' +Position get for item '-3' +Position set for item '-4' ").VerifyDiagnostics() verifier.VerifyIL("Program.Call1(Of T)", ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Class_Async_01() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_IndexAndValue_Async_01() Dim comp = @@ -2620,7 +7690,7 @@ Imports System Imports System.Threading.Tasks Interface IMoveable - Property Position As Integer + Property Position(x As Integer) As Integer End Interface Class Item @@ -2628,7 +7698,7 @@ Class Item Public Property Name As String - Public Property Position As Integer Implements IMoveable.Position + Public Property Position(x As Integer) As Integer Implements IMoveable.Position Get Console.WriteLine("Position get for item '{0}'", Me.Name) Return 0 @@ -2649,11 +7719,11 @@ Class Program End Sub Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task - item.Position += await GetOffsetAsync(GetOffset(item)) + item.Position(GetOffset(item)) += await GetOffsetAsync(GetOffset(item)) End Function Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - item.Position += await GetOffsetAsync(GetOffset(item)) + item.Position(GetOffset(item)) += await GetOffsetAsync(GetOffset(item)) End Function Shared value as Integer @@ -2674,373 +7744,238 @@ End Class ' Wrong output Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " -Position get for item '1' -Position set for item '-1' -Position get for item '2' +Position get for item '-1' Position set for item '-2' +Position get for item '-3' +Position set for item '-4' ").VerifyDiagnostics() 'Wrong IL verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) - - 'Wrong IL - verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", - ) - End Sub - - - - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Struct_Async_01() - Dim comp = - - -Imports System -Imports System.Threading.Tasks - -Interface IMoveable - Property Position As Integer -End Interface - -Structure Item - Implements IMoveable - - Public Property Name As String - - Public Property Position As Integer Implements IMoveable.Position - Get - Console.WriteLine("Position get for item '{0}'", Me.Name) - Return 0 - End Get - Set - Console.WriteLine("Position set for item '{0}'", Me.Name) - End Set - End Property -End Structure - -Class Program - Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} - Call1(item1).Wait() - - Dim item2 = New Item With {.Name = "2"} - Call2(item2).Wait() - End Sub - - Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T) As Task - item.Position += await GetOffsetAsync(GetOffset(item)) - End Function - - Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - item.Position += await GetOffsetAsync(GetOffset(item)) - End Function - - Shared value as Integer - - Shared Function GetOffset(Of T)(ByRef item As T) As Integer - value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) - Return 0 - End Function - - Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) - Return Task.FromResult(i) - End Function -End Class - - - - Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= -" -Position get for item '1' -Position set for item '-1' -Position get for item '2' -Position set for item '-2' -").VerifyDiagnostics() - verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Class_Async_02() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_IndexAndValue_Async_01() Dim comp = @@ -3048,15 +7983,15 @@ Imports System Imports System.Threading.Tasks Interface IMoveable - Property Position As Integer + Property Position(x As Integer) As Integer End Interface -Class Item +Structure Item Implements IMoveable Public Property Name As String - Public Property Position As Integer Implements IMoveable.Position + Public Property Position(x As Integer) As Integer Implements IMoveable.Position Get Console.WriteLine("Position get for item '{0}'", Me.Name) Return 0 @@ -3065,7 +8000,7 @@ Class Item Console.WriteLine("Position set for item '{0}'", Me.Name) End Set End Property -End Class +End Structure Class Program Shared Sub Main() @@ -3076,14 +8011,12 @@ Class Program Call2(item2).Wait() End Sub - Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task - await Task.Yield() - item.Position += await GetOffsetAsync(GetOffset(item)) + Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T) As Task + item.Position(GetOffset(item)) += await GetOffsetAsync(GetOffset(item)) End Function Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - await Task.Yield() - item.Position += await GetOffsetAsync(GetOffset(item)) + item.Position(GetOffset(item)) += await GetOffsetAsync(GetOffset(item)) End Function Shared value as Integer @@ -3101,150 +8034,292 @@ End Class - ' Wrong output Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " -Position get for item '1' -Position set for item '-1' -Position get for item '2' +Position get for item '-1' Position set for item '-2' +Position get for item '-3' +Position set for item '-4' ").VerifyDiagnostics() - 'Wrong IL verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_IndexAndValue_Async_03() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1).Wait() + + Dim item2 = New Item With {.Name = "2"} + Call2(item2).Wait() + End Sub + + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task + item.Position(await GetOffsetAsync(GetOffset(item))) += GetOffset(item) + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + item.Position(await GetOffsetAsync(GetOffset(item))) += GetOffset(item) + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function +End Class + + + + ' Wrong output and framework dependent + ' Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= + '" + 'Position get for item '-1' + 'Position set for item '-1' + 'Position get for item '-3' + 'Position set for item '-3' + '").VerifyDiagnostics() + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe).VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + ) @@ -3252,144 +8327,105 @@ Position set for item '-2' verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Property_Struct_Async_02() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_IndexAndValue_Async_03() Dim comp = @@ -3397,212 +8433,172 @@ Imports System Imports System.Threading.Tasks Interface IMoveable - Property Position As Integer + Property Position(x As Integer) As Integer End Interface Structure Item Implements IMoveable - - Public Property Name As String - - Public Property Position As Integer Implements IMoveable.Position - Get - Console.WriteLine("Position get for item '{0}'", Me.Name) - Return 0 - End Get - Set - Console.WriteLine("Position set for item '{0}'", Me.Name) - End Set - End Property -End Structure - -Class Program - Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} - Call1(item1).Wait() - - Dim item2 = New Item With {.Name = "2"} - Call2(item2).Wait() - End Sub - - Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T) As Task - await Task.Yield() - item.Position += await GetOffsetAsync(GetOffset(item)) - End Function - - Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - await Task.Yield() - item.Position += await GetOffsetAsync(GetOffset(item)) - End Function - - Shared value as Integer - - Shared Function GetOffset(Of T)(ByRef item As T) As Integer - value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) - Return 0 - End Function - - Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) - Return Task.FromResult(i) - End Function -End Class - - - - Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= -" -Position get for item '1' -Position set for item '-1' -Position get for item '2' -Position set for item '-2' -").VerifyDiagnostics() - - verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", - + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-2' +Position get for item '-3' +Position set for item '-4' +").VerifyDiagnostics() + + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_IndexAndValue_Async_04() Dim comp = Imports System +Imports System.Threading.Tasks Interface IMoveable Property Position(x As Integer) As Integer @@ -3627,19 +8623,19 @@ End Class Class Program Shared Sub Main() Dim item1 = New Item With {.Name = "1"} - Call1(item1) + Call1(item1).Wait() Dim item2 = New Item With {.Name = "2"} - Call2(item2) + Call2(item2).Wait() End Sub - Private Shared Sub Call1(Of T As {Class, IMoveable})(item As T) - item.Position(GetOffset(item)) += 1 - End Sub + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task + item.Position(await GetOffsetAsync(GetOffset(item))) += await GetOffsetAsync(GetOffset(item)) + End Function - Private Shared Sub Call2(Of T As {IMoveable})(item As T) - item.Position(GetOffset(item)) += 1 - End Sub + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + item.Position(await GetOffsetAsync(GetOffset(item))) += await GetOffsetAsync(GetOffset(item)) + End Function Shared value as Integer @@ -3648,6 +8644,10 @@ Class Program item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) Return 0 End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function End Class @@ -3656,67 +8656,320 @@ End Class Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " Position get for item '-1' -Position set for item '-1' -Position get for item '-2' Position set for item '-2' +Position get for item '-3' +Position set for item '-4' ").VerifyDiagnostics() 'Wrong IL - verifier.VerifyIL("Program.Call1(Of T)", + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) 'Wrong IL - verifier.VerifyIL("Program.Call2(Of T)", + verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_IndexAndValue_Async_04() Dim comp = Imports System +Imports System.Threading.Tasks Interface IMoveable Property Position(x As Integer) As Integer @@ -3741,19 +8994,19 @@ End Structure Class Program Shared Sub Main() Dim item1 = New Item With {.Name = "1"} - Call1(item1) + Call1(item1).Wait() Dim item2 = New Item With {.Name = "2"} - Call2(item2) + Call2(item2).Wait() End Sub - Private Shared Sub Call1(Of T As {Structure, IMoveable})(item As T) - item.Position(GetOffset(item)) += 1 - End Sub + Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T) As Task + item.Position(await GetOffsetAsync(GetOffset(item))) += await GetOffsetAsync(GetOffset(item)) + End Function - Private Shared Sub Call2(Of T As {IMoveable})(item As T) - item.Position(GetOffset(item)) += 1 - End Sub + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + item.Position(await GetOffsetAsync(GetOffset(item))) += await GetOffsetAsync(GetOffset(item)) + End Function Shared value as Integer @@ -3762,159 +9015,175 @@ Class Program item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) Return 0 End Function -End Class - - - - Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= -" -Position get for item '-1' -Position set for item '-1' -Position get for item '-2' -Position set for item '-2' -").VerifyDiagnostics() - - verifier.VerifyIL("Program.Call1(Of T)", - ) - End Sub - - - - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index_Ref() - Dim comp = - - -Imports System - -Interface IMoveable - Property Position(x As Integer) As Integer -End Interface - -Class Item - Implements IMoveable - - Public Property Name As String - - Public Property Position(x As Integer) As Integer Implements IMoveable.Position - Get - Console.WriteLine("Position get for item '{0}'", Me.Name) - Return 0 - End Get - Set - Console.WriteLine("Position set for item '{0}'", Me.Name) - End Set - End Property -End Class - -Class Program - Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} - Call1(item1) - - Dim item2 = New Item With {.Name = "2"} - Call2(item2) - End Sub - Private Shared Sub Call1(Of T As {Class, IMoveable})(ByRef item As T) - item.Position(GetOffset(item)) += 1 - End Sub - - Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) - item.Position(GetOffset(item)) += 1 - End Sub - - Shared value as Integer - - Shared Function GetOffset(Of T)(ByRef item As T) As Integer - value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) - Return 0 + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) End Function End Class - ' Wrong output Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " Position get for item '-1' -Position set for item '-1' -Position get for item '-2' Position set for item '-2' +Position get for item '-3' +Position set for item '-4' ").VerifyDiagnostics() - 'Wrong IL - verifier.VerifyIL("Program.Call1(Of T)", - ) - - 'Wrong IL - verifier.VerifyIL("Program.Call2(Of T)", + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index_Ref() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index_InWith() Dim comp = @@ -3924,7 +9193,7 @@ Interface IMoveable Property Position(x As Integer) As Integer End Interface -Structure Item +Class Item Implements IMoveable Public Property Name As String @@ -3938,7 +9207,7 @@ Structure Item Console.WriteLine("Position set for item '{0}'", Me.Name) End Set End Property -End Structure +End Class Class Program Shared Sub Main() @@ -3949,103 +9218,18 @@ Class Program Call2(item2) End Sub - Private Shared Sub Call1(Of T As {Structure, IMoveable})(ByRef item As T) - item.Position(GetOffset(item)) += 1 - End Sub - - Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) - item.Position(GetOffset(item)) += 1 + Private Shared Sub Call1(Of T As {Class, IMoveable})(item As T) + With item + .Position(GetOffset(item)) += 1 + End With End Sub - Shared value as Integer - - Shared Function GetOffset(Of T)(ByRef item As T) As Integer - value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) - Return 0 - End Function -End Class - - - - Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= -" -Position get for item '-1' -Position set for item '-1' -Position get for item '-2' -Position set for item '-2' -").VerifyDiagnostics() - - verifier.VerifyIL("Program.Call1(Of T)", - ) - End Sub - - - - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index_Async_01() - Dim comp = - - -Imports System -Imports System.Threading.Tasks - -Interface IMoveable - Property Position(x As Integer) As Integer -End Interface - -Class Item - Implements IMoveable - - Public Property Name As String - - Public Property Position(x As Integer) As Integer Implements IMoveable.Position - Get - Console.WriteLine("Position get for item '{0}'", Me.Name) - Return 0 - End Get - Set - Console.WriteLine("Position set for item '{0}'", Me.Name) - End Set - End Property -End Class - -Class Program - Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} - Call1(item1).Wait() - - Dim item2 = New Item With {.Name = "2"} - Call2(item2).Wait() + Private Shared Sub Call2(Of T As {IMoveable})(item As T) + With item + .Position(GetOffset(item)) += 1 + End With End Sub - Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task - item.Position(await GetOffsetAsync(GetOffset(item))) += 1 - End Function - - Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - item.Position(await GetOffsetAsync(GetOffset(item))) += 1 - End Function - Shared value as Integer Shared Function GetOffset(Of T)(ByRef item As T) As Integer @@ -4053,10 +9237,6 @@ Class Program item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) Return 0 End Function - - Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) - Return Task.FromResult(i) - End Function End Class @@ -4071,208 +9251,61 @@ Position set for item '-2' ").VerifyDiagnostics() 'Wrong IL - verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + verifier.VerifyIL("Program.Call1(Of T)", ) 'Wrong IL - verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", + verifier.VerifyIL("Program.Call2(Of T)", ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index_Async_01() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index_InWith() Dim comp = Imports System -Imports System.Threading.Tasks Interface IMoveable Property Position(x As Integer) As Integer @@ -4297,19 +9330,23 @@ End Structure Class Program Shared Sub Main() Dim item1 = New Item With {.Name = "1"} - Call1(item1).Wait() + Call1(item1) Dim item2 = New Item With {.Name = "2"} - Call2(item2).Wait() + Call2(item2) End Sub - Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T) As Task - item.Position(await GetOffsetAsync(GetOffset(item))) += 1 - End Function + Private Shared Sub Call1(Of T As {Structure, IMoveable})(item As T) + With item + .Position(GetOffset(item)) += 1 + End With + End Sub - Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - item.Position(await GetOffsetAsync(GetOffset(item))) += 1 - End Function + Private Shared Sub Call2(Of T As {IMoveable})(item As T) + With item + .Position(GetOffset(item)) += 1 + End With + End Sub Shared value as Integer @@ -4318,10 +9355,6 @@ Class Program item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) Return 0 End Function - - Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) - Return Task.FromResult(i) - End Function End Class @@ -4334,122 +9367,166 @@ Position get for item '-2' Position set for item '-2' ").VerifyDiagnostics() - verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + verifier.VerifyIL("Program.Call1(Of T)", ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index_Ref_InWith() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1) + + Dim item2 = New Item With {.Name = "2"} + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Class, IMoveable})(ByRef item As T) + With item + .Position(GetOffset(item)) += 1 + End With + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) + With item + .Position(GetOffset(item)) += 1 + End With + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function +End Class + + + + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.Call1(Of T)", + ) + + 'Wrong IL + verifier.VerifyIL("Program.Call2(Of T)", + ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index_Async_02() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index_Ref_InWith() Dim comp = Imports System -Imports System.Threading.Tasks Interface IMoveable - Property Position(x as Integer) As Integer + Property Position(x As Integer) As Integer End Interface -Class Item +Structure Item Implements IMoveable Public Property Name As String - Public Property Position(x as Integer) As Integer Implements IMoveable.Position + Public Property Position(x As Integer) As Integer Implements IMoveable.Position Get Console.WriteLine("Position get for item '{0}'", Me.Name) Return 0 @@ -4458,26 +9535,28 @@ Class Item Console.WriteLine("Position set for item '{0}'", Me.Name) End Set End Property -End Class +End Structure Class Program Shared Sub Main() Dim item1 = New Item With {.Name = "1"} - Call1(item1).Wait() + Call1(item1) Dim item2 = New Item With {.Name = "2"} - Call2(item2).Wait() + Call2(item2) End Sub - Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task - await Task.Yield() - item.Position(await GetOffsetAsync(GetOffset(item))) += 1 - End Function + Private Shared Sub Call1(Of T As {Structure, IMoveable})(ByRef item As T) + With item + .Position(GetOffset(item)) += 1 + End With + End Sub - Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - await Task.Yield() - item.Position(await GetOffsetAsync(GetOffset(item))) += 1 - End Function + Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) + With item + .Position(GetOffset(item)) += 1 + End With + End Sub Shared value as Integer @@ -4486,15 +9565,10 @@ Class Program item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) Return 0 End Function - - Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) - Return Task.FromResult(i) - End Function End Class - ' Wrong output Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " Position get for item '-1' @@ -4503,288 +9577,302 @@ Position get for item '-2' Position set for item '-2' ").VerifyDiagnostics() - 'Wrong IL - verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", + verifier.VerifyIL("Program.Call1(Of T)", ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index_Async_01_InWith() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Program + Shared Sub Main() + Dim item1 = New Item With {.Name = "1"} + Call1(item1).Wait() + + Dim item2 = New Item With {.Name = "2"} + Call2(item2).Wait() + End Sub + + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task + With item + .Position(await GetOffsetAsync(GetOffset(item))) += 1 + End With + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task + With item + .Position(await GetOffsetAsync(GetOffset(item))) += 1 + End With + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T) As Integer + value -= 1 + item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function +End Class + + + + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() 'Wrong IL - verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) + + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", + ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index_Async_02() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index_Async_01_InWith() Dim comp = @@ -4792,7 +9880,7 @@ Imports System Imports System.Threading.Tasks Interface IMoveable - Property Position(x as Integer) As Integer + Property Position(x As Integer) As Integer End Interface Structure Item @@ -4800,7 +9888,7 @@ Structure Item Public Property Name As String - Public Property Position(x as Integer) As Integer Implements IMoveable.Position + Public Property Position(x As Integer) As Integer Implements IMoveable.Position Get Console.WriteLine("Position get for item '{0}'", Me.Name) Return 0 @@ -4821,13 +9909,15 @@ Class Program End Sub Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T) As Task - await Task.Yield() - item.Position(await GetOffsetAsync(GetOffset(item))) += 1 + With item + .Position(await GetOffsetAsync(GetOffset(item))) += 1 + End With End Function Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - await Task.Yield() - item.Position(await GetOffsetAsync(GetOffset(item))) += 1 + With item + .Position(await GetOffsetAsync(GetOffset(item))) += 1 + End With End Function Shared value as Integer @@ -4856,145 +9946,103 @@ Position set for item '-2' verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Value() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Value_InWith() Dim comp = @@ -5030,11 +10078,15 @@ Class Program End Sub Private Shared Sub Call1(Of T As {Class, IMoveable})(item As T) - item.Position(1) += GetOffset(item) + With item + .Position(1) += GetOffset(item) + End With End Sub Private Shared Sub Call2(Of T As {IMoveable})(item As T) - item.Position(1) += GetOffset(item) + With item + .Position(1) += GetOffset(item) + End With End Sub Shared value as Integer @@ -5103,7 +10155,7 @@ End Class - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Value() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Value_InWith() Dim comp = @@ -5139,11 +10191,15 @@ Class Program End Sub Private Shared Sub Call1(Of T As {Structure, IMoveable})(item As T) - item.Position(1) += GetOffset(item) + With item + .Position(1) += GetOffset(item) + End With End Sub Private Shared Sub Call2(Of T As {IMoveable})(item As T) - item.Position(1) += GetOffset(item) + With item + .Position(1) += GetOffset(item) + End With End Sub Shared value as Integer @@ -5188,7 +10244,7 @@ Position set for item '-2' - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Value_Ref() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Value_Ref_InWith() Dim comp = @@ -5224,11 +10280,15 @@ Class Program End Sub Private Shared Sub Call1(Of T As {Class, IMoveable})(ByRef item As T) - item.Position(1) += GetOffset(item) + With item + .Position(1) += GetOffset(item) + End With End Sub Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) - item.Position(1) += GetOffset(item) + With item + .Position(1) += GetOffset(item) + End With End Sub Shared value as Integer @@ -5297,7 +10357,7 @@ End Class - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Value_Ref() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Value_Ref_InWith() Dim comp = @@ -5333,11 +10393,15 @@ Class Program End Sub Private Shared Sub Call1(Of T As {Structure, IMoveable})(ByRef item As T) - item.Position(1) += GetOffset(item) + With item + .Position(1) += GetOffset(item) + End With End Sub Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) - item.Position(1) += GetOffset(item) + With item + .Position(1) += GetOffset(item) + End With End Sub Shared value as Integer @@ -5382,7 +10446,7 @@ Position set for item '-2' - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Value_Async_01() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Value_Async_01_InWith() Dim comp = @@ -5419,11 +10483,15 @@ Class Program End Sub Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task - item.Position(1) += await GetOffsetAsync(GetOffset(item)) + With item + .Position(1) += await GetOffsetAsync(GetOffset(item)) + End With End Function Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - item.Position(1) += await GetOffsetAsync(GetOffset(item)) + With item + .Position(1) += await GetOffsetAsync(GetOffset(item)) + End With End Function Shared value as Integer @@ -5649,7 +10717,7 @@ Position set for item '-2' - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Value_Async_01() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Value_Async_01_InWith() Dim comp = @@ -5686,11 +10754,15 @@ Class Program End Sub Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T) As Task - item.Position(1) += await GetOffsetAsync(GetOffset(item)) + With item + .Position(1) += await GetOffsetAsync(GetOffset(item)) + End With End Function Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - item.Position(1) += await GetOffsetAsync(GetOffset(item)) + With item + .Position(1) += await GetOffsetAsync(GetOffset(item)) + End With End Function Shared value as Integer @@ -5816,7 +10888,7 @@ Position set for item '-2' - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_IndexAndValue() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index_ThroughArray() Dim comp = @@ -5842,102 +10914,583 @@ Class Item End Property End Class +Class Item2 + Inherits Item +End Class + Class Program Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} + Dim item1 = { New Item2 With {.Name = "1"} } + Call1(DirectCast(item1, Item())) + + Dim item2 = { New Item2 With {.Name = "2"} } + Call2(DirectCast(item2, Item())) + End Sub + + Private Shared Sub Call1(Of T As {Class, IMoveable})(item As T()) + item(GetArrayIndex()).Position(GetOffset(item)) += 1 + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(item As T()) + item(GetArrayIndex()).Position(GetOffset(item)) += 1 + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(item As T()) As Integer + value -= 1 + item(0) = DirectCast(DirectCast(New Item2 With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetArrayIndex() As Integer + Return 0 + End Function +End Class + + + + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.Call1(Of T)", + ) + + 'Wrong IL + verifier.VerifyIL("Program.Call2(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index_ThroughArray() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Structure + +Class Program + Shared Sub Main() + Dim item1 = { New Item With {.Name = "1"} } Call1(item1) - Dim item2 = New Item With {.Name = "2"} + Dim item2 = { New Item With {.Name = "2"} } Call2(item2) End Sub - Private Shared Sub Call1(Of T As {Class, IMoveable})(item As T) - item.Position(GetOffset(item)) += GetOffset(item) + Private Shared Sub Call1(Of T As {Structure, IMoveable})(item As T()) + item(GetArrayIndex()).Position(GetOffset(item)) += 1 End Sub - Private Shared Sub Call2(Of T As {IMoveable})(item As T) - item.Position(GetOffset(item)) += GetOffset(item) + Private Shared Sub Call2(Of T As {IMoveable})(item As T()) + item(GetArrayIndex()).Position(GetOffset(item)) += 1 + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(item As T()) As Integer + value -= 1 + item(0) = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetArrayIndex() As Integer + Return 0 + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() + + verifier.VerifyIL("Program.Call1(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index_Async_01_ThroughArray() + Dim comp = + + +Imports System +Imports System.Threading.Tasks + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Item2 + Inherits Item +End Class + +Class Program + Shared Sub Main() + Dim item1 = { New Item2 With {.Name = "1"} } + Call1(DirectCast(item1, Item())).Wait() + + Dim item2 = { New Item2 With {.Name = "2"} } + Call2(DirectCast(item2, Item())).Wait() End Sub - Shared value as Integer + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T()) As Task + item(GetArrayIndex()).Position(await GetOffsetAsync(GetOffset(item))) += 1 + End Function + + Private Shared Async Function Call2(Of T As {IMoveable})(item As T()) As Task + item(GetArrayIndex()).Position(await GetOffsetAsync(GetOffset(item))) += 1 + End Function + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer + value -= 1 + item(0) = DirectCast(DirectCast(New Item2 With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function - Shared Function GetOffset(Of T)(ByRef item As T) As Integer - value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Shared Function GetArrayIndex() As Integer Return 0 End Function End Class - ' Wrong output and differs, but still wrong, on some frameworks - ' Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= - '" - 'Position get for item '-1' - 'Position set for item '-1' - 'Position get for item '-3' - 'Position set for item '-3' - '").VerifyDiagnostics() - Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe).VerifyDiagnostics() + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() 'Wrong IL - verifier.VerifyIL("Program.Call1(Of T)", + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) 'Wrong IL - verifier.VerifyIL("Program.Call2(Of T)", + verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_IndexAndValue() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index_Async_01_ThroughArray() Dim comp = Imports System +Imports System.Threading.Tasks Interface IMoveable Property Position(x As Integer) As Integer @@ -5961,26 +11514,34 @@ End Structure Class Program Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} - Call1(item1) + Dim item1 = { New Item With {.Name = "1"} } + Call1(item1).Wait() - Dim item2 = New Item With {.Name = "2"} - Call2(item2) + Dim item2 = { New Item With {.Name = "2"} } + Call2(item2).Wait() End Sub - Private Shared Sub Call1(Of T As {Structure, IMoveable})(item As T) - item.Position(GetOffset(item)) += GetOffset(item) - End Sub + Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T()) As Task + item(GetArrayIndex()).Position(await GetOffsetAsync(GetOffset(item))) += 1 + End Function - Private Shared Sub Call2(Of T As {IMoveable})(item As T) - item.Position(GetOffset(item)) += GetOffset(item) - End Sub + Private Shared Async Function Call2(Of T As {IMoveable})(item As T()) As Task + item(GetArrayIndex()).Position(await GetOffsetAsync(GetOffset(item))) += 1 + End Function Shared value as Integer - Shared Function GetOffset(Of T)(ByRef item As T) As Integer + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + item(0) = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) + Return Task.FromResult(i) + End Function + + Shared Function GetArrayIndex() As Integer Return 0 End Function End Class @@ -5990,39 +11551,148 @@ End Class Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " Position get for item '-1' +Position set for item '-1' +Position get for item '-2' Position set for item '-2' -Position get for item '-3' -Position set for item '-4' ").VerifyDiagnostics() - verifier.VerifyIL("Program.Call1(Of T)", + verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_IndexAndValue_Ref() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Value_ThroughArray() Dim comp = @@ -6048,98 +11718,120 @@ Class Item End Property End Class +Class Item2 + Inherits Item +End Class + Class Program Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} - Call1(item1) + Dim item1 = { New Item2 With {.Name = "1"} } + Call1(DirectCast(item1, Item())) - Dim item2 = New Item With {.Name = "2"} - Call2(item2) + Dim item2 = { New Item2 With {.Name = "2"} } + Call2(DirectCast(item2, Item())) End Sub - Private Shared Sub Call1(Of T As {Class, IMoveable})(ByRef item As T) - item.Position(GetOffset(item)) += GetOffset(item) + Private Shared Sub Call1(Of T As {Class, IMoveable})(item As T()) + item(GetArrayIndex()).Position(1) += GetOffset(item) End Sub - Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) - item.Position(GetOffset(item)) += GetOffset(item) + Private Shared Sub Call2(Of T As {IMoveable})(item As T()) + item(GetArrayIndex()).Position(1) += GetOffset(item) End Sub Shared value as Integer - Shared Function GetOffset(Of T)(ByRef item As T) As Integer + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + item(0) = DirectCast(DirectCast(New Item2 With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetArrayIndex() As Integer Return 0 End Function End Class - ' Wrong output and framework dependent - ' Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= - '" - 'Position get for item '-1' - 'Position set for item '-1' - 'Position get for item '-3' - 'Position set for item '-3' - '").VerifyDiagnostics() - Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe).VerifyDiagnostics() + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '1' +Position set for item '1' +Position get for item '2' +Position set for item '2' +").VerifyDiagnostics() 'Wrong IL verifier.VerifyIL("Program.Call1(Of T)", ) 'Wrong IL verifier.VerifyIL("Program.Call2(Of T)", - ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_IndexAndValue_Ref() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Value_ThroughArray() Dim comp = @@ -6167,26 +11859,30 @@ End Structure Class Program Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} + Dim item1 = { New Item With {.Name = "1"} } Call1(item1) - Dim item2 = New Item With {.Name = "2"} + Dim item2 = { New Item With {.Name = "2"} } Call2(item2) End Sub - Private Shared Sub Call1(Of T As {Structure, IMoveable})(ByRef item As T) - item.Position(GetOffset(item)) += GetOffset(item) + Private Shared Sub Call1(Of T As {Structure, IMoveable})(item As T()) + item(GetArrayIndex()).Position(1) += GetOffset(item) End Sub - Private Shared Sub Call2(Of T As {IMoveable})(ByRef item As T) - item.Position(GetOffset(item)) += GetOffset(item) + Private Shared Sub Call2(Of T As {IMoveable})(item As T()) + item(GetArrayIndex()).Position(1) += GetOffset(item) End Sub Shared value as Integer - Shared Function GetOffset(Of T)(ByRef item As T) As Integer + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + item(0) = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetArrayIndex() As Integer Return 0 End Function End Class @@ -6195,40 +11891,48 @@ End Class Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " -Position get for item '-1' +Position get for item '1' +Position set for item '-1' +Position get for item '2' Position set for item '-2' -Position get for item '-3' -Position set for item '-4' ").VerifyDiagnostics() verifier.VerifyIL("Program.Call1(Of T)", ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_IndexAndValue_Async_01() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Value_Async_01_ThroughArray() Dim comp = @@ -6239,6 +11943,10 @@ Interface IMoveable Property Position(x As Integer) As Integer End Interface +Class Item2 + Inherits Item +End Class + Class Item Implements IMoveable @@ -6257,32 +11965,36 @@ End Class Class Program Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} - Call1(item1).Wait() + Dim item1 = { New Item2 With {.Name = "1"} } + Call1(DirectCast(item1, Item())).Wait() - Dim item2 = New Item With {.Name = "2"} - Call2(item2).Wait() + Dim item2 = { New Item2 With {.Name = "2"} } + Call2(DirectCast(item2, Item())).Wait() End Sub - Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task - item.Position(GetOffset(item)) += await GetOffsetAsync(GetOffset(item)) + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T()) As Task + item(GetArrayIndex()).Position(1) += await GetOffsetAsync(GetOffset(item)) End Function - Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - item.Position(GetOffset(item)) += await GetOffsetAsync(GetOffset(item)) + Private Shared Async Function Call2(Of T As {IMoveable})(item As T()) As Task + item(GetArrayIndex()).Position(1) += await GetOffsetAsync(GetOffset(item)) End Function Shared value as Integer - Shared Function GetOffset(Of T)(ByRef item As T) As Integer + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + item(0) = DirectCast(DirectCast(New Item2 With {.Name = value.ToString()}, IMoveable), T) Return 0 End Function Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) Return Task.FromResult(i) End Function + + Shared Function GetArrayIndex() As Integer + Return 0 + End Function End Class @@ -6290,238 +12002,286 @@ End Class ' Wrong output Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " -Position get for item '-1' +Position get for item '1' +Position set for item '-1' +Position get for item '2' Position set for item '-2' -Position get for item '-3' -Position set for item '-4' ").VerifyDiagnostics() 'Wrong IL verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) - - 'Wrong IL - verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", - ) + + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", + ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_IndexAndValue_Async_01() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Value_Async_01_ThroughArray() Dim comp = @@ -6550,158 +12310,450 @@ End Structure Class Program Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} + Dim item1 = { New Item With {.Name = "1"} } Call1(item1).Wait() - Dim item2 = New Item With {.Name = "2"} + Dim item2 = { New Item With {.Name = "2"} } Call2(item2).Wait() End Sub - Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T) As Task - item.Position(GetOffset(item)) += await GetOffsetAsync(GetOffset(item)) + Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T()) As Task + item(GetArrayIndex()).Position(1) += await GetOffsetAsync(GetOffset(item)) End Function - Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - item.Position(GetOffset(item)) += await GetOffsetAsync(GetOffset(item)) + Private Shared Async Function Call2(Of T As {IMoveable})(item As T()) As Task + item(GetArrayIndex()).Position(1) += await GetOffsetAsync(GetOffset(item)) End Function Shared value as Integer - Shared Function GetOffset(Of T)(ByRef item As T) As Integer + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + item(0) = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) Return 0 End Function Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) Return Task.FromResult(i) End Function + + Shared Function GetArrayIndex() As Integer + Return 0 + End Function End Class Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " -Position get for item '-1' +Position get for item '1' +Position set for item '-1' +Position get for item '2' Position set for item '-2' -Position get for item '-3' -Position set for item '-4' ").VerifyDiagnostics() verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index_ThroughArray_InWith() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Item2 + Inherits Item +End Class + +Class Program + Shared Sub Main() + Dim item1 = { New Item2 With {.Name = "1"} } + Call1(DirectCast(item1, Item())) + + Dim item2 = { New Item2 With {.Name = "2"} } + Call2(DirectCast(item2, Item())) + End Sub + + Private Shared Sub Call1(Of T As {Class, IMoveable})(item As T()) + With item(GetArrayIndex()) + .Position(GetOffset(item)) += 1 + End With + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(item As T()) + With item(GetArrayIndex()) + .Position(GetOffset(item)) += 1 + End With + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(item As T()) As Integer + value -= 1 + item(0) = DirectCast(DirectCast(New Item2 With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetArrayIndex() As Integer + Return 0 + End Function +End Class + + + + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.Call1(Of T)", + ) + + 'Wrong IL + verifier.VerifyIL("Program.Call2(Of T)", + ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_IndexAndValue_Async_03() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index_ThroughArray_InWith() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Structure + +Class Program + Shared Sub Main() + Dim item1 = { New Item With {.Name = "1"} } + Call1(item1) + + Dim item2 = { New Item With {.Name = "2"} } + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Structure, IMoveable})(item As T()) + With item(GetArrayIndex()) + .Position(GetOffset(item)) += 1 + End With + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(item As T()) + With item(GetArrayIndex()) + .Position(GetOffset(item)) += 1 + End With + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(item As T()) As Integer + value -= 1 + item(0) = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetArrayIndex() As Integer + Return 0 + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() + + verifier.VerifyIL("Program.Call1(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Index_Async_01_ThroughArray_InWith() Dim comp = @@ -6728,53 +12780,64 @@ Class Item End Property End Class +Class Item2 + Inherits Item +End Class + Class Program Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} - Call1(item1).Wait() + Dim item1 = { New Item2 With {.Name = "1"} } + Call1(DirectCast(item1, Item())).Wait() - Dim item2 = New Item With {.Name = "2"} - Call2(item2).Wait() + Dim item2 = { New Item2 With {.Name = "2"} } + Call2(DirectCast(item2, Item())).Wait() End Sub - Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task - item.Position(await GetOffsetAsync(GetOffset(item))) += GetOffset(item) + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T()) As Task + With item(GetArrayIndex()) + .Position(await GetOffsetAsync(GetOffset(item))) += 1 + End With End Function - Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - item.Position(await GetOffsetAsync(GetOffset(item))) += GetOffset(item) + Private Shared Async Function Call2(Of T As {IMoveable})(item As T()) As Task + With item(GetArrayIndex()) + .Position(await GetOffsetAsync(GetOffset(item))) += 1 + End With End Function Shared value as Integer - Shared Function GetOffset(Of T)(ByRef item As T) As Integer + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + item(0) = DirectCast(DirectCast(New Item2 With {.Name = value.ToString()}, IMoveable), T) Return 0 End Function Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) Return Task.FromResult(i) End Function + + Shared Function GetArrayIndex() As Integer + Return 0 + End Function End Class - ' Wrong output and framework dependent - ' Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= - '" - 'Position get for item '-1' - 'Position set for item '-1' - 'Position get for item '-3' - 'Position set for item '-3' - '").VerifyDiagnostics() - Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe).VerifyDiagnostics() + ' Wrong output + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '-1' +Position set for item '-1' +Position get for item '-2' +Position set for item '-2' +").VerifyDiagnostics() 'Wrong IL verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) @@ -6873,7 +12970,7 @@ End Class verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_IndexAndValue_Async_03() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Index_Async_01_ThroughArray_InWith() Dim comp = @@ -7000,32 +13131,40 @@ End Structure Class Program Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} + Dim item1 = { New Item With {.Name = "1"} } Call1(item1).Wait() - Dim item2 = New Item With {.Name = "2"} + Dim item2 = { New Item With {.Name = "2"} } Call2(item2).Wait() End Sub - Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T) As Task - item.Position(await GetOffsetAsync(GetOffset(item))) += GetOffset(item) + Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T()) As Task + With item(GetArrayIndex()) + .Position(await GetOffsetAsync(GetOffset(item))) += 1 + End With End Function - Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - item.Position(await GetOffsetAsync(GetOffset(item))) += GetOffset(item) + Private Shared Async Function Call2(Of T As {IMoveable})(item As T()) As Task + With item(GetArrayIndex()) + .Position(await GetOffsetAsync(GetOffset(item))) += 1 + End With End Function Shared value as Integer - Shared Function GetOffset(Of T)(ByRef item As T) As Integer + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + item(0) = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) Return 0 End Function Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) Return Task.FromResult(i) End Function + + Shared Function GetArrayIndex() As Integer + Return 0 + End Function End Class @@ -7033,15 +13172,15 @@ End Class Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " Position get for item '-1' +Position set for item '-1' +Position get for item '-2' Position set for item '-2' -Position get for item '-3' -Position set for item '-4' ").VerifyDiagnostics() verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Value_ThroughArray_InWith() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Class Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Class + +Class Item2 + Inherits Item +End Class + +Class Program + Shared Sub Main() + Dim item1 = { New Item2 With {.Name = "1"} } + Call1(DirectCast(item1, Item())) + + Dim item2 = { New Item2 With {.Name = "2"} } + Call2(DirectCast(item2, Item())) + End Sub + + Private Shared Sub Call1(Of T As {Class, IMoveable})(item As T()) + With item(GetArrayIndex()) + .Position(1) += GetOffset(item) + End With + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(item As T()) + With item(GetArrayIndex()) + .Position(1) += GetOffset(item) + End With + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer + value -= 1 + item(0) = DirectCast(DirectCast(New Item2 With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetArrayIndex() As Integer + Return 0 + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '1' +Position set for item '1' +Position get for item '2' +Position set for item '2' +").VerifyDiagnostics() + + 'Wrong IL + verifier.VerifyIL("Program.Call1(Of T)", + ) + + 'Wrong IL + verifier.VerifyIL("Program.Call2(Of T)", + ) + End Sub + + + + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Value_ThroughArray_InWith() + Dim comp = + + +Imports System + +Interface IMoveable + Property Position(x As Integer) As Integer +End Interface + +Structure Item + Implements IMoveable + + Public Property Name As String + + Public Property Position(x As Integer) As Integer Implements IMoveable.Position + Get + Console.WriteLine("Position get for item '{0}'", Me.Name) + Return 0 + End Get + Set + Console.WriteLine("Position set for item '{0}'", Me.Name) + End Set + End Property +End Structure + +Class Program + Shared Sub Main() + Dim item1 = { New Item With {.Name = "1"} } + Call1(item1) + + Dim item2 = { New Item With {.Name = "2"} } + Call2(item2) + End Sub + + Private Shared Sub Call1(Of T As {Structure, IMoveable})(item As T()) + With item(GetArrayIndex()) + .Position(1) += GetOffset(item) + End With + End Sub + + Private Shared Sub Call2(Of T As {IMoveable})(item As T()) + With item(GetArrayIndex()) + .Position(1) += GetOffset(item) + End With + End Sub + + Shared value as Integer + + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer + value -= 1 + item(0) = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + Return 0 + End Function + + Shared Function GetArrayIndex() As Integer + Return 0 + End Function +End Class + + + + Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= +" +Position get for item '1' +Position set for item '-1' +Position get for item '2' +Position set for item '-2' +").VerifyDiagnostics() + + verifier.VerifyIL("Program.Call1(Of T)", + ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_IndexAndValue_Async_04() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Class_Value_Async_01_ThroughArray_InWith() Dim comp = @@ -7150,6 +13577,10 @@ Interface IMoveable Property Position(x As Integer) As Integer End Interface +Class Item2 + Inherits Item +End Class + Class Item Implements IMoveable @@ -7168,32 +13599,40 @@ End Class Class Program Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} - Call1(item1).Wait() + Dim item1 = { New Item2 With {.Name = "1"} } + Call1(DirectCast(item1, Item())).Wait() - Dim item2 = New Item With {.Name = "2"} - Call2(item2).Wait() + Dim item2 = { New Item2 With {.Name = "2"} } + Call2(DirectCast(item2, Item())).Wait() End Sub - Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T) As Task - item.Position(await GetOffsetAsync(GetOffset(item))) += await GetOffsetAsync(GetOffset(item)) + Private Shared Async Function Call1(Of T As {Class, IMoveable})(item As T()) As Task + With item(GetArrayIndex()) + .Position(1) += await GetOffsetAsync(GetOffset(item)) + End With End Function - Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - item.Position(await GetOffsetAsync(GetOffset(item))) += await GetOffsetAsync(GetOffset(item)) + Private Shared Async Function Call2(Of T As {IMoveable})(item As T()) As Task + With item(GetArrayIndex()) + .Position(1) += await GetOffsetAsync(GetOffset(item)) + End With End Function Shared value as Integer - Shared Function GetOffset(Of T)(ByRef item As T) As Integer + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + item(0) = DirectCast(DirectCast(New Item2 With {.Name = value.ToString()}, IMoveable), T) Return 0 End Function Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) Return Task.FromResult(i) End Function + + Shared Function GetArrayIndex() As Integer + Return 0 + End Function End Class @@ -7201,22 +13640,22 @@ End Class ' Wrong output Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " -Position get for item '-1' +Position get for item '1' +Position set for item '-1' +Position get for item '2' Position set for item '-2' -Position get for item '-3' -Position set for item '-4' ").VerifyDiagnostics() 'Wrong IL verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) - - 'Wrong IL - verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", - ) + + 'Wrong IL + verifier.VerifyIL("Program.VB$StateMachine_3_Call2(Of SM$T).MoveNext()", + ) End Sub - Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_IndexAndValue_Async_04() + Public Sub GenericTypeParameterAsReceiver_Assignment_Compound_Indexer_Struct_Value_Async_01_ThroughArray_InWith() Dim comp = @@ -7539,53 +13936,61 @@ End Structure Class Program Shared Sub Main() - Dim item1 = New Item With {.Name = "1"} + Dim item1 = { New Item With {.Name = "1"} } Call1(item1).Wait() - Dim item2 = New Item With {.Name = "2"} + Dim item2 = { New Item With {.Name = "2"} } Call2(item2).Wait() End Sub - Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T) As Task - item.Position(await GetOffsetAsync(GetOffset(item))) += await GetOffsetAsync(GetOffset(item)) + Private Shared Async Function Call1(Of T As {Structure, IMoveable})(item As T()) As Task + With item(GetArrayIndex()) + .Position(1) += await GetOffsetAsync(GetOffset(item)) + End With End Function - Private Shared Async Function Call2(Of T As {IMoveable})(item As T) As Task - item.Position(await GetOffsetAsync(GetOffset(item))) += await GetOffsetAsync(GetOffset(item)) + Private Shared Async Function Call2(Of T As {IMoveable})(item As T()) As Task + With item(GetArrayIndex()) + .Position(1) += await GetOffsetAsync(GetOffset(item)) + End With End Function Shared value as Integer - Shared Function GetOffset(Of T)(ByRef item As T) As Integer + Shared Function GetOffset(Of T)(ByRef item As T()) As Integer value -= 1 - item = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) + item(0) = DirectCast(DirectCast(New Item With {.Name = value.ToString()}, IMoveable), T) Return 0 End Function Shared Function GetOffsetAsync(i As Integer) As Task(Of Integer) Return Task.FromResult(i) End Function + + Shared Function GetArrayIndex() As Integer + Return 0 + End Function End Class Dim verifier = CompileAndVerifyEx(comp, targetFramework:=TargetFramework.StandardAndVBRuntime, options:=TestOptions.ReleaseExe, expectedOutput:= " -Position get for item '-1' +Position get for item '1' +Position set for item '-1' +Position get for item '2' Position set for item '-2' -Position get for item '-3' -Position set for item '-4' ").VerifyDiagnostics() verifier.VerifyIL("Program.VB$StateMachine_2_Call1(Of SM$T).MoveNext()", ) End Sub diff --git a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenRefReturnTests.vb b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenRefReturnTests.vb index fe8645255f49f..237f366ee1cf6 100644 --- a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenRefReturnTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenRefReturnTests.vb @@ -425,6 +425,585 @@ End Module", verifier.VerifyDiagnostics() End Sub + + + Public Sub DefaultPropertyAsTheTargetInCompoundAssignment() + Dim comp1 = CreateCSharpCompilation( +"public class C +{ +#pragma warning disable 0649 + public T[] P; + + public ref T this[int index] + { + get + { + System.Console.WriteLine(""get_this""); + ref T x = ref P[index]; + P = new T[10]; + return ref x; + } + } +}") + comp1.VerifyDiagnostics() + Dim comp2 = CreateVisualBasicCompilation( + Nothing, +"Module M + Sub Main() + Dim a As Integer() = { 100 } + Dim o = New C(Of Integer) With { .P = a } + Test(o) + System.Console.WriteLine(a(0)) + End Sub + + Sub Test(o As C(Of Integer)) + o(GetIndex()) += 2 + End Sub + + Function GetIndex() As Integer + System.Console.WriteLine(""GetIndex"") + return 0 + End Function +End Module", + referencedCompilations:={comp1}, + compilationOptions:=TestOptions.DebugExe) + Dim verifier = CompileAndVerify(comp2, expectedOutput:=" +GetIndex +get_this +get_this +2 +") + verifier.VerifyIL("M.Test", + ) + verifier.VerifyDiagnostics() + End Sub + + + Public Sub MethodAsTheTargetInCompoundAssignment() + Dim comp1 = CreateCSharpCompilation( +"public class C +{ +#pragma warning disable 0649 + public T[] P; + + public ref T M(int index) + { + System.Console.WriteLine(""get_this""); + ref T x = ref P[index]; + P = new T[10]; + return ref x; + } +}") + comp1.VerifyDiagnostics() + Dim comp2 = CreateVisualBasicCompilation( + Nothing, +"Module M + Sub Main() + Dim a As Integer() = { 100 } + Dim o = New C(Of Integer) With { .P = a } + Test(o) + System.Console.WriteLine(a(0)) + End Sub + + Sub Test(o As C(Of Integer)) + o.M(GetIndex()) += 2 + End Sub + + Function GetIndex() As Integer + System.Console.WriteLine(""GetIndex"") + return 0 + End Function +End Module", + referencedCompilations:={comp1}, + compilationOptions:=TestOptions.DebugExe) + Dim verifier = CompileAndVerify(comp2, expectedOutput:=" +GetIndex +get_this +102 +") + verifier.VerifyIL("M.Test", + ) + verifier.VerifyDiagnostics() + End Sub + + + Public Sub DefaultPropertyAsByRefArgument() + Dim comp1 = CreateCSharpCompilation( +"public class C +{ +#pragma warning disable 0649 + public T[] P; + + public ref T this[int index] + { + get + { + System.Console.WriteLine(""get_this""); + ref T x = ref P[index]; + P = new T[10]; + return ref x; + } + } +}") + comp1.VerifyDiagnostics() + Dim comp2 = CreateVisualBasicCompilation( + Nothing, +"Module M + Sub Main() + Dim a As Integer() = { 100 } + Dim o = New C(Of Integer) With { .P = a } + Test(o) + System.Console.WriteLine(a(0)) + End Sub + + Sub Test(o As C(Of Integer)) + M(o(GetIndex())) + End Sub + + Sub M(ByRef x as Integer) + x += 2 + End Sub + + Function GetIndex() As Integer + System.Console.WriteLine(""GetIndex"") + return 0 + End Function +End Module", + referencedCompilations:={comp1}, + compilationOptions:=TestOptions.DebugExe) + Dim verifier = CompileAndVerify(comp2, expectedOutput:=" +GetIndex +get_this +102 +") + verifier.VerifyIL("M.Test", + ) + verifier.VerifyDiagnostics() + End Sub + + + Public Sub MethodAsByRefArgument() + Dim comp1 = CreateCSharpCompilation( +"public class C +{ +#pragma warning disable 0649 + public T[] P; + + public ref T M(int index) + { + System.Console.WriteLine(""get_this""); + ref T x = ref P[index]; + P = new T[10]; + return ref x; + } +}") + comp1.VerifyDiagnostics() + Dim comp2 = CreateVisualBasicCompilation( + Nothing, +"Module M + Sub Main() + Dim a As Integer() = { 100 } + Dim o = New C(Of Integer) With { .P = a } + Test(o) + System.Console.WriteLine(a(0)) + End Sub + + Sub Test(o As C(Of Integer)) + M(o.M(GetIndex())) + End Sub + + Sub M(ByRef x as Integer) + x += 2 + End Sub + + Function GetIndex() As Integer + System.Console.WriteLine(""GetIndex"") + return 0 + End Function +End Module", + referencedCompilations:={comp1}, + compilationOptions:=TestOptions.DebugExe) + Dim verifier = CompileAndVerify(comp2, expectedOutput:=" +GetIndex +get_this +102 +") + verifier.VerifyIL("M.Test", + ) + verifier.VerifyDiagnostics() + End Sub + + + + Public Sub DefaultPropertyAsByRefArgumentWithCopyBack() + Dim comp1 = CreateCSharpCompilation( +"public class C +{ +#pragma warning disable 0649 + public T[] P; + + public ref T this[int index] + { + get + { + System.Console.WriteLine(""get_this""); + ref T x = ref P[index]; + P = new T[10]; + return ref x; + } + } +}") + comp1.VerifyDiagnostics() + Dim comp2 = CreateVisualBasicCompilation( + Nothing, +"Module M + Sub Main() + Dim a As Integer() = { 100 } + Dim o = New C(Of Integer) With { .P = a } + Test(o) + System.Console.WriteLine(a(0)) + End Sub + + Sub Test(o As C(Of Integer)) + M(o(GetIndex())) + End Sub + + Sub M(ByRef x as Long) + x += 2 + End Sub + + Function GetIndex() As Integer + System.Console.WriteLine(""GetIndex"") + return 0 + End Function +End Module", + referencedCompilations:={comp1}, + compilationOptions:=TestOptions.DebugExe) + Dim verifier = CompileAndVerify(comp2, expectedOutput:=" +GetIndex +get_this +get_this +100 +") + verifier.VerifyIL("M.Test", + ) + verifier.VerifyDiagnostics() + End Sub + + + Public Sub MethodAsByRefArgumentWithCopyBack() + Dim comp1 = CreateCSharpCompilation( +"public class C +{ +#pragma warning disable 0649 + public T[] P; + + public ref T M(int index) + { + System.Console.WriteLine(""get_this""); + ref T x = ref P[index]; + P = new T[10]; + return ref x; + } +}") + comp1.VerifyDiagnostics() + Dim comp2 = CreateVisualBasicCompilation( + Nothing, +"Module M + Sub Main() + Dim a As Integer() = { 100 } + Dim o = New C(Of Integer) With { .P = a } + Test(o) + System.Console.WriteLine(a(0)) + End Sub + + Sub Test(o As C(Of Integer)) + M(o.M(GetIndex())) + End Sub + + Sub M(ByRef x as Long) + x += 2 + End Sub + + Function GetIndex() As Integer + System.Console.WriteLine(""GetIndex"") + return 0 + End Function +End Module", + referencedCompilations:={comp1}, + compilationOptions:=TestOptions.DebugExe) + Dim verifier = CompileAndVerify(comp2, expectedOutput:=" +GetIndex +get_this +102 +") + verifier.VerifyIL("M.Test", + ) + verifier.VerifyDiagnostics() + End Sub + + + + Public Sub DefaultPropertyAsReceiverOfTheTargetInCompoundAssignment() + Dim comp1 = CreateCSharpCompilation( +"public class C +{ +#pragma warning disable 0649 + public S[] P; + + public ref S this[int index] + { + get + { + System.Console.WriteLine(""get_this""); + ref S x = ref P[index]; + P = new[] { new S() }; + return ref x; + } + } +} + +public struct S +{ + public int F {get; set;} +} +") + comp1.VerifyDiagnostics() + Dim comp2 = CreateVisualBasicCompilation( + Nothing, +"Module M + Sub Main() + Dim a As S() = { new S() with { .F = 100 } } + Dim o = New C() With { .P = a } + Test(o) + System.Console.WriteLine(a(0).F) + End Sub + + Sub Test(o As C) + o(GetIndex()).F += 2 + End Sub + + Sub Test2(ByRef x As S) + x.F += 2 + End Sub + + Function GetIndex() As Integer + System.Console.WriteLine(""GetIndex"") + return 0 + End Function +End Module", + referencedCompilations:={comp1}, + compilationOptions:=TestOptions.DebugExe) + + comp2.AssertTheseDiagnostics( + +BC30068: Expression is a value and therefore cannot be the target of an assignment. + o(GetIndex()).F += 2 + ~~~~~~~~~~~~~~~ + + ) + ' Dim verifier = CompileAndVerify(comp2, expectedOutput:=" + '") + ' verifier.VerifyIL("M.Test", + ' ) + ' verifier.VerifyDiagnostics() + End Sub + + + Public Sub MethodAsReceiverOfTheTargetInCompoundAssignment() + Dim comp1 = CreateCSharpCompilation( +"public class C +{ +#pragma warning disable 0649 + public S[] P; + + public ref S M(int index) + { + System.Console.WriteLine(""get_this""); + ref S x = ref P[index]; + P = new[] { new S() }; + return ref x; + } +} + +public struct S +{ + public int F {get; set;} +} +") + comp1.VerifyDiagnostics() + Dim comp2 = CreateVisualBasicCompilation( + Nothing, +"Module M + Sub Main() + Dim a As S() = { new S() with { .F = 100 } } + Dim o = New C() With { .P = a } + Test(o) + System.Console.WriteLine(a(0).F) + End Sub + + Sub Test(o As C) + o.M(GetIndex()).F += 2 + End Sub + + Function GetIndex() As Integer + System.Console.WriteLine(""GetIndex"") + return 0 + End Function +End Module", + referencedCompilations:={comp1}, + compilationOptions:=TestOptions.DebugExe) + + Dim verifier = CompileAndVerify(comp2, expectedOutput:=" +GetIndex +get_this +102 +") + verifier.VerifyIL("M.Test", + ) + verifier.VerifyDiagnostics() + End Sub + Public Sub PropertyArgument() Dim comp1 = CreateCSharpCompilation(