diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/GenerateMethod/GenerateMethodTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/GenerateMethod/GenerateMethodTests.cs index e380d0d5c16ab..756e9b5fd17d2 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/GenerateMethod/GenerateMethodTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/GenerateMethod/GenerateMethodTests.cs @@ -2879,6 +2879,46 @@ private static void OnChanged(object sender, EventArgs e) }"); } + [WorkItem(10004, "https://github.com/dotnet/roslyn/issues/10004")] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)] + public async Task TestGenerateMethodWithMultipleOfSameGenericType() + { + await TestAsync( +@"using System; + +public class C +{ +} + +public static class Ex +{ + public static T M1(this T t) where T : C + { + return [|t.M()|]; + } +} +", +@"using System; + +public class C +{ + internal T2 M() + where T1 : C + where T2 : C + { + } +} + +public static class Ex +{ + public static T M1(this T t) where T : C + { + return t.M(); + } +} +"); + } + public class GenerateConversionTest : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest { internal override Tuple CreateDiagnosticProviderAndFixer(Workspace workspace) diff --git a/src/EditorFeatures/VisualBasicTest/Diagnostics/GenerateMethod/GenerateMethodTests.vb b/src/EditorFeatures/VisualBasicTest/Diagnostics/GenerateMethod/GenerateMethodTests.vb index 2415cd30bd63f..fc1c07b5b7098 100644 --- a/src/EditorFeatures/VisualBasicTest/Diagnostics/GenerateMethod/GenerateMethodTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Diagnostics/GenerateMethod/GenerateMethodTests.vb @@ -2200,6 +2200,38 @@ NewLines("Imports System \n Imports System.Collections.Generic \n Module Program NewLines("Imports System \n Imports System.Collections.Generic \n Module Program \n Sub M() \n Dim x = New Dictionary ( Of Integer , Boolean ) From { { 1, T() } } \n End Sub \n Private Function T() As Boolean \n Throw New NotImplementedException() \n End Function \n End Module")) End Function + + + Public Async Function TestGenerateMethodWithMultipleOfSameGenericType() As Task + Await TestAsync( + +Namespace TestClasses + Public Class C + End Class + + Module Ex + Public Function M(Of T As C)(a As T) As T + Return [|a.Test(Of T, T)()|] + End Function + End Module +End Namespace +.Value.Replace(vbLf, vbCrLf), + +Namespace TestClasses + Public Class C + Friend Function Test(Of T1 As C, T2 As C)() As T2 + End Function + End Class + + Module Ex + Public Function M(Of T As C)(a As T) As T + Return a.Test(Of T, T)() + End Function + End Module +End Namespace +.Value.Replace(vbLf, vbCrLf)) + End Function + Public Class GenerateConversionTests Inherits AbstractVisualBasicDiagnosticProviderBasedUserDiagnosticTest @@ -2484,7 +2516,6 @@ Class Digit End Class .Value.Replace(vbLf, vbCrLf), compareTokens:=False) End Function - End Class End Class End Namespace diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs index d5b17e85de6b0..b36a4a8af95be 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs @@ -67,7 +67,7 @@ public static IMethodSymbol RenameTypeParameters(this IMethodSymbol method, ILis var mapping = new Dictionary(); for (int i = 0; i < method.TypeParameters.Length; i++) { - mapping.Add(method.TypeParameters[i], updatedTypeParameters[i]); + mapping[method.TypeParameters[i]] = updatedTypeParameters[i]; } return CodeGenerationSymbolFactory.CreateMethodSymbol( @@ -131,7 +131,7 @@ public static IMethodSymbol RenameParameters(this IMethodSymbol method, IList