Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ private static async Task<Document> ReplaceWithMethodName(Document document, Syn
if (nodeToReplace is null)
return document;

var newNode = nodeToFix.ReplaceNode(nodeToReplace, generator.IdentifierName(methodName));
var newMethodName = nodeToReplace switch
{
GenericNameSyntax genericName => generator.GenericName(methodName, genericName.TypeArgumentList.Arguments),
_ => generator.IdentifierName(methodName),
};
var newNode = nodeToFix.ReplaceNode(nodeToReplace, newMethodName);
var newExpression = generator.AwaitExpression(newNode).Parentheses();
editor.ReplaceNode(nodeToFix, newExpression);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,50 @@ public async Task A()
.ValidateAsync();
}

[Fact]
public async Task FixerKeepsGenericArgument()
{
await CreateProjectBuilder()
.WithSourceCode(
@"using System.Threading.Tasks;
class Buz
{
private static async Task Do()
{
[||]Bar.Foo<int>();
}
}

class Bar
{
public static T Foo<T>()
=> default;

public static Task<T> FooAsync<T>()
=> Task.FromResult(default(T));
}")
.ShouldFixCodeWith(
@"using System.Threading.Tasks;
class Buz
{
private static async Task Do()
{
await Bar.FooAsync<int>();
}
}

class Bar
{
public static T Foo<T>()
=> default;

public static Task<T> FooAsync<T>()
=> Task.FromResult(default(T));
}")
.ValidateAsync();
}


[Fact]
public async Task Async_Wait_Int32_Diagnostic()
{
Expand Down
Loading