Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing global alias on method argument in inlined user-implemented method #1629 #1630

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
5 changes: 3 additions & 2 deletions src/Riok.Mapperly/Descriptors/InlineExpressionRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,16 @@ public override SyntaxNode VisitThrowExpression(ThrowExpressionSyntax node)
return node;
}

private static InvocationExpressionSyntax VisitStaticMethodInvocation(InvocationExpressionSyntax node, IMethodSymbol methodSymbol)
private InvocationExpressionSyntax VisitStaticMethodInvocation(InvocationExpressionSyntax node, IMethodSymbol methodSymbol)
{
var receiverType = FullyQualifiedIdentifier(methodSymbol.ReceiverType!);
SimpleNameSyntax method = methodSymbol.TypeArguments is { Length: > 0 } typeArguments
? GenericName(methodSymbol.Name)
.WithTypeArgumentList(TypeArgumentList(SeparatedList<TypeSyntax>(typeArguments.Select(FullyQualifiedIdentifier))))
: IdentifierName(methodSymbol.Name);
var expression = MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, receiverType, method);
return node.WithExpression(expression);
var arguments = (ArgumentListSyntax)Visit(node.ArgumentList);
return node.WithExpression(expression).WithArgumentList(arguments);
}

private InvocationExpressionSyntax VisitExtensionMethodInvocation(InvocationExpressionSyntax node, IMethodSymbol methodSymbol)
Expand Down
17 changes: 17 additions & 0 deletions test/Riok.Mapperly.Tests/Mapping/QueryableProjectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ public Task RecordToRecordManualFlatteningInsideList()
return TestHelper.VerifyGenerator(source);
}

[Fact]
public Task RecordToRecordManualMappingWithGlobalTypeArgsInInliningMappingMethod()
{
var source = TestSourceBuilder.MapperWithBodyAndTypes(
"""
public partial IQueryable<B> ProjectAToB(IQueryable<A> query);

public DateTimeOffset MapDateTimeToDateTimeOffset(DateTime value) =>
value != DateTime.MinValue ? new DateTimeOffset(DateTime.SpecifyKind(value, DateTimeKind.Utc)) : DateTimeOffset.MinValue;
""",
"public sealed record A(string Name, DateTime ChangedOn);",
"public sealed record B(string Name, DateTimeOffset ChangedOn);"
);

return TestHelper.VerifyGenerator(source);
}

[Fact]
public Task RecordToRecordManualListMapping()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
public partial class Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
public partial global::System.Linq.IQueryable<global::B> ProjectAToB(global::System.Linq.IQueryable<global::A> query)
{
#nullable disable
return System.Linq.Queryable.Select(
query,
x => new global::B(
x.Name,
x.ChangedOn != global::System.DateTime.MinValue ? new global::System.DateTimeOffset(global::System.DateTime.SpecifyKind(x.ChangedOn, global::System.DateTimeKind.Utc)) : global::System.DateTimeOffset.MinValue
)
);
#nullable enable
}
}
Loading