@@ -294,6 +294,118 @@ static void Main() { }
294294 Handle ( 2 , TableIndex . AssemblyRef ) ) ;
295295 }
296296
297+ [ Fact ]
298+ public void ModifyMethod_RenameParameter ( )
299+ {
300+ var source0 =
301+ @"class C
302+ {
303+ static void Main() { }
304+ static string F(int a) { return a.ToString(); }
305+ }" ;
306+ var source1 =
307+ @"class C
308+ {
309+ static void Main() { }
310+ static string F(int x) { return x.ToString(); }
311+ }" ;
312+ var source2 =
313+ @"class C
314+ {
315+ static void Main() { }
316+ static string F(int b) { return b.ToString(); }
317+ }" ;
318+
319+ var compilation0 = CreateCompilation ( source0 , options : TestOptions . DebugExe ) ;
320+ var compilation1 = compilation0 . WithSource ( source1 ) ;
321+ var compilation2 = compilation1 . WithSource ( source2 ) ;
322+
323+ var method0 = compilation0 . GetMember < MethodSymbol > ( "C.F" ) ;
324+
325+ // Verify full metadata contains expected rows.
326+ var bytes0 = compilation0 . EmitToArray ( EmitOptions . Default . WithDebugInformationFormat ( DebugInformationFormat . PortablePdb ) ) ;
327+ using var md0 = ModuleMetadata . CreateFromImage ( bytes0 ) ;
328+ var reader0 = md0 . MetadataReader ;
329+
330+ CheckNames ( reader0 , reader0 . GetTypeDefNames ( ) , "<Module>" , "C" ) ;
331+ CheckNames ( reader0 , reader0 . GetMethodDefNames ( ) , "Main" , "F" , ".ctor" ) ;
332+ CheckNames ( reader0 , reader0 . GetMemberRefNames ( ) , /*CompilationRelaxationsAttribute.*/ ".ctor" , /*RuntimeCompatibilityAttribute.*/ ".ctor" , /*Object.*/ ".ctor" , "ToString" , /*DebuggableAttribute*/ ".ctor" ) ;
333+ CheckNames ( reader0 , reader0 . GetParameterDefNames ( ) , "a" ) ;
334+
335+ var generation0 = EmitBaseline . CreateInitialBaseline (
336+ md0 ,
337+ EmptyLocalsProvider ) ;
338+ var method1 = compilation1 . GetMember < MethodSymbol > ( "C.F" ) ;
339+
340+ var diff1 = compilation1 . EmitDifference (
341+ generation0 ,
342+ ImmutableArray . Create ( SemanticEdit . Create ( SemanticEditKind . Update , method0 , method1 ) ) ) ;
343+
344+ // Verify delta metadata contains expected rows.
345+ using var md1 = diff1 . GetMetadata ( ) ;
346+ var reader1 = md1 . Reader ;
347+ var readers = new [ ] { reader0 , reader1 } ;
348+
349+ EncValidation . VerifyModuleMvid ( 1 , reader0 , reader1 ) ;
350+
351+ CheckNames ( readers , reader1 . GetTypeDefNames ( ) ) ;
352+ CheckNames ( readers , reader1 . GetMethodDefNames ( ) , "F" ) ;
353+ CheckNames ( readers , reader1 . GetMemberRefNames ( ) , "ToString" ) ;
354+ CheckNames ( readers , reader1 . GetParameterDefNames ( ) , "x" ) ;
355+
356+ CheckEncLog ( reader1 ,
357+ Row ( 2 , TableIndex . AssemblyRef , EditAndContinueOperation . Default ) ,
358+ Row ( 6 , TableIndex . MemberRef , EditAndContinueOperation . Default ) ,
359+ Row ( 7 , TableIndex . TypeRef , EditAndContinueOperation . Default ) ,
360+ Row ( 8 , TableIndex . TypeRef , EditAndContinueOperation . Default ) ,
361+ Row ( 2 , TableIndex . StandAloneSig , EditAndContinueOperation . Default ) ,
362+ Row ( 2 , TableIndex . MethodDef , EditAndContinueOperation . Default ) ,
363+ Row ( 1 , TableIndex . Param , EditAndContinueOperation . Default ) ) ;
364+
365+ CheckEncMap ( reader1 ,
366+ Handle ( 7 , TableIndex . TypeRef ) ,
367+ Handle ( 8 , TableIndex . TypeRef ) ,
368+ Handle ( 2 , TableIndex . MethodDef ) ,
369+ Handle ( 1 , TableIndex . Param ) ,
370+ Handle ( 6 , TableIndex . MemberRef ) ,
371+ Handle ( 2 , TableIndex . StandAloneSig ) ,
372+ Handle ( 2 , TableIndex . AssemblyRef ) ) ;
373+
374+ var method2 = compilation2 . GetMember < MethodSymbol > ( "C.F" ) ;
375+
376+ var diff2 = compilation2 . EmitDifference (
377+ diff1 . NextGeneration ,
378+ ImmutableArray . Create ( SemanticEdit . Create ( SemanticEditKind . Update , method1 , method2 ) ) ) ;
379+
380+ // Verify delta metadata contains expected rows.
381+ using var md2 = diff2 . GetMetadata ( ) ;
382+ var reader2 = md2 . Reader ;
383+ readers = new [ ] { reader0 , reader1 , reader2 } ;
384+
385+ CheckNames ( readers , reader2 . GetTypeDefNames ( ) ) ;
386+ CheckNames ( readers , reader2 . GetMethodDefNames ( ) , "F" ) ;
387+ CheckNames ( readers , reader2 . GetMemberRefNames ( ) , "ToString" ) ;
388+ CheckNames ( readers , reader2 . GetParameterDefNames ( ) , "b" ) ;
389+
390+ CheckEncLog ( reader2 ,
391+ Row ( 3 , TableIndex . AssemblyRef , EditAndContinueOperation . Default ) ,
392+ Row ( 7 , TableIndex . MemberRef , EditAndContinueOperation . Default ) ,
393+ Row ( 9 , TableIndex . TypeRef , EditAndContinueOperation . Default ) ,
394+ Row ( 10 , TableIndex . TypeRef , EditAndContinueOperation . Default ) ,
395+ Row ( 3 , TableIndex . StandAloneSig , EditAndContinueOperation . Default ) ,
396+ Row ( 2 , TableIndex . MethodDef , EditAndContinueOperation . Default ) ,
397+ Row ( 1 , TableIndex . Param , EditAndContinueOperation . Default ) ) ;
398+
399+ CheckEncMap ( reader2 ,
400+ Handle ( 9 , TableIndex . TypeRef ) ,
401+ Handle ( 10 , TableIndex . TypeRef ) ,
402+ Handle ( 2 , TableIndex . MethodDef ) ,
403+ Handle ( 1 , TableIndex . Param ) ,
404+ Handle ( 7 , TableIndex . MemberRef ) ,
405+ Handle ( 3 , TableIndex . StandAloneSig ) ,
406+ Handle ( 3 , TableIndex . AssemblyRef ) ) ;
407+ }
408+
297409 [ CompilerTrait ( CompilerFeature . Tuples ) ]
298410 [ Fact ]
299411 public void ModifyMethod_WithTuples ( )
@@ -11811,5 +11923,89 @@ public void TopLevelStatement_Update()
1181111923 Handle ( 7 , TableIndex . MemberRef ) ,
1181211924 Handle ( 2 , TableIndex . AssemblyRef ) ) ;
1181311925 }
11926+
11927+ [ Fact ]
11928+ public void LambdaParameterToDiscard ( )
11929+ {
11930+ var source0 = MarkedSource ( @"
11931+ using System;
11932+ class C
11933+ {
11934+ void M()
11935+ {
11936+ var x = new Func<int, int, int>(<N:0>(a, b) => a + b + 1</N:0>);
11937+ Console.WriteLine(x(1, 2));
11938+ }
11939+ }" ) ;
11940+ var source1 = MarkedSource ( @"
11941+ using System;
11942+ class C
11943+ {
11944+ void M()
11945+ {
11946+ var x = new Func<int, int, int>(<N:0>(_, _) => 10</N:0>);
11947+ Console.WriteLine(x(1, 2));
11948+ }
11949+ }" ) ;
11950+
11951+ var compilation0 = CreateCompilation ( source0 . Tree , options : ComSafeDebugDll ) ;
11952+ var compilation1 = compilation0 . WithSource ( source1 . Tree ) ;
11953+
11954+ var method0 = compilation0 . GetMember < MethodSymbol > ( "C.M" ) ;
11955+ var method1 = compilation1 . GetMember < MethodSymbol > ( "C.M" ) ;
11956+
11957+ var v0 = CompileAndVerify ( compilation0 , verify : Verification . Skipped ) ;
11958+
11959+ using var md0 = ModuleMetadata . CreateFromImage ( v0 . EmittedAssemblyData ) ;
11960+
11961+ var generation0 = EmitBaseline . CreateInitialBaseline ( md0 , v0 . CreateSymReader ( ) . GetEncMethodDebugInfo ) ;
11962+
11963+ var diff = compilation1 . EmitDifference (
11964+ generation0 ,
11965+ ImmutableArray . Create (
11966+ SemanticEdit . Create ( SemanticEditKind . Update , method0 , method1 , GetSyntaxMapFromMarkers ( source0 , source1 ) , preserveLocalVariables : true ) ) ) ;
11967+
11968+ // There should be no diagnostics from rude edits
11969+ diff . EmitResult . Diagnostics . Verify ( ) ;
11970+
11971+ diff . VerifySynthesizedMembers (
11972+ "C: {<>c}" ,
11973+ "C.<>c: {<>9__0_0, <M>b__0_0}" ) ;
11974+
11975+ diff . VerifyIL ( "C.M" ,
11976+ @"
11977+ {
11978+ // Code size 48 (0x30)
11979+ .maxstack 3
11980+ .locals init ([unchanged] V_0,
11981+ System.Func<int, int, int> V_1) //x
11982+ IL_0000: nop
11983+ IL_0001: ldsfld ""System.Func<int, int, int> C.<>c.<>9__0_0""
11984+ IL_0006: dup
11985+ IL_0007: brtrue.s IL_0020
11986+ IL_0009: pop
11987+ IL_000a: ldsfld ""C.<>c C.<>c.<>9""
11988+ IL_000f: ldftn ""int C.<>c.<M>b__0_0(int, int)""
11989+ IL_0015: newobj ""System.Func<int, int, int>..ctor(object, System.IntPtr)""
11990+ IL_001a: dup
11991+ IL_001b: stsfld ""System.Func<int, int, int> C.<>c.<>9__0_0""
11992+ IL_0020: stloc.1
11993+ IL_0021: ldloc.1
11994+ IL_0022: ldc.i4.1
11995+ IL_0023: ldc.i4.2
11996+ IL_0024: callvirt ""int System.Func<int, int, int>.Invoke(int, int)""
11997+ IL_0029: call ""void System.Console.WriteLine(int)""
11998+ IL_002e: nop
11999+ IL_002f: ret
12000+ }" ) ;
12001+
12002+ diff . VerifyIL ( "C.<>c.<M>b__0_0(int, int)" , @"
12003+ {
12004+ // Code size 3 (0x3)
12005+ .maxstack 1
12006+ IL_0000: ldc.i4.s 10
12007+ IL_0002: ret
12008+ }" ) ;
12009+ }
1181412010 }
1181512011}
0 commit comments