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
9 changes: 5 additions & 4 deletions src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1875,16 +1875,17 @@ private InvocationExpressionSyntax UnwrapExtension(InvocationExpressionSyntax ie
var newName = reducedFrom.Name;
newName = changeMemoryToSpan ? GetNewName(reducedFrom) : RemoveAsync(newName);

var newNameExistsInContainingType = semanticModel.Compilation.References
var membersWithNewNameInContainingType = semanticModel.Compilation.References
.Select(semanticModel.Compilation.GetAssemblyOrModuleSymbol)
.Append(semanticModel.Compilation.Assembly)
.OfType<IAssemblySymbol>()
.Select(assemblySymbol => assemblySymbol.GetTypeByMetadataName(reducedFrom.ContainingType.ToString()))
.OfType<INamedTypeSymbol>()
.SelectMany(symbol => symbol.GetMembers(newName))
.Any();
.SelectMany(symbol => symbol.GetMembers(newName));

var fullyQualifiedName = newNameExistsInContainingType
// When the method is an AsyncEnumerable extension it must be converted to the corresponding Enumerable extension
// regardless of the containing type featuring members with compatible names
var fullyQualifiedName = !reducedFrom.ContainingType.Name.Equals("AsyncEnumerable", StringComparison.Ordinal) && membersWithNewNameInContainingType.Any()
? $"{reducedFrom.ContainingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}.{newName}"
: $"{MakeType(reducedFrom.ContainingType)}.{newName}";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//HintName: Test.Class.MethodAsync.g.cs
public void Method(global::System.Collections.Generic.IEnumerable<int> foo)
{
var elements = global::System.Linq.Enumerable.ToList(global::System.Linq.Enumerable.Where(global::System.Linq.Enumerable.Select(foo, i => i + 5), i => i > 0));
}
11 changes: 11 additions & 0 deletions tests/Generator.Tests/SystemAsyncExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,15 @@ internal static async Task MethodAsync(IAsyncEnumerable<int> enumerable, Cancell
}
}
""".Verify(sourceType: SourceType.Full);

#if NET
[Fact]
public Task LinqConversion() => """
[Zomp.SyncMethodGenerator.CreateSyncVersion]
public async Task MethodAsync(IAsyncEnumerable<int> foo)
{
var elements = await foo.Select(i => i + 5).Where(i => i > 0).ToListAsync();
}
""".Verify();
#endif
}
Loading