Skip to content

Commit

Permalink
Fix #47 Translate FromResult<T> properly when type parameter is speci…
Browse files Browse the repository at this point in the history
…fied explicitly
  • Loading branch information
virzak committed Jan 21, 2024
1 parent 23e00d5 commit 0a03982
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,14 @@ bool IsValidParameter(ParameterSyntax ps)
return UnwrapExtension(@base, isMemory, reducedFrom, memberAccess.Expression);
}

if (memberAccess.Name is not IdentifierNameSyntax { Identifier.ValueText: { } name })
var name = memberAccess.Name switch
{
IdentifierNameSyntax ins2 => ins2.Identifier.ValueText,
GenericNameSyntax gns => gns.Identifier.ValueText,
_ => null,
};

if (name is null)
{
return @base;
}
Expand Down
10 changes: 6 additions & 4 deletions tests/Generator.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,16 @@ public async Task MyFuncAsync<T>()
}
""".Verify();

[Fact]
public Task TaskOfT() => """
[Theory]
[InlineData(true)]
[InlineData(false)]
public Task TaskOfT(bool explicitType) => $$"""
[CreateSyncVersion]
public static async Task<Point> GetPointAsync()
{
return await Task.FromResult(new Point(1, 2));
return await Task.FromResult{{(explicitType ? "<Point>" : string.Empty)}}(new Point(1, 2));
}
""".Verify();
""".Verify(disableUnique: true);

[Fact]
public Task TaskOfTArray() => """
Expand Down

0 comments on commit 0a03982

Please sign in to comment.