diff --git a/src/Riok.Mapperly/Descriptors/InlineExpressionRewriter.cs b/src/Riok.Mapperly/Descriptors/InlineExpressionRewriter.cs index 8f1ec31966..f8fefcce39 100644 --- a/src/Riok.Mapperly/Descriptors/InlineExpressionRewriter.cs +++ b/src/Riok.Mapperly/Descriptors/InlineExpressionRewriter.cs @@ -226,7 +226,7 @@ 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 @@ -234,7 +234,8 @@ private static InvocationExpressionSyntax VisitStaticMethodInvocation(Invocation .WithTypeArgumentList(TypeArgumentList(SeparatedList(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) diff --git a/test/Riok.Mapperly.Tests/Mapping/QueryableProjectionTest.cs b/test/Riok.Mapperly.Tests/Mapping/QueryableProjectionTest.cs index fb1928a7a9..9fd6bb798f 100644 --- a/test/Riok.Mapperly.Tests/Mapping/QueryableProjectionTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/QueryableProjectionTest.cs @@ -116,6 +116,23 @@ public Task RecordToRecordManualFlatteningInsideList() return TestHelper.VerifyGenerator(source); } + [Fact] + public Task RecordToRecordManualMappingWithGlobalTypeArgsInInliningMappingMethod() + { + var source = TestSourceBuilder.MapperWithBodyAndTypes( + """ + public partial IQueryable ProjectAToB(IQueryable 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() { diff --git a/test/Riok.Mapperly.Tests/_snapshots/QueryableProjectionTest.RecordToRecordManualMappingWithGlobalTypeArgsInInliningMappingMethod#Mapper.g.verified.cs b/test/Riok.Mapperly.Tests/_snapshots/QueryableProjectionTest.RecordToRecordManualMappingWithGlobalTypeArgsInInliningMappingMethod#Mapper.g.verified.cs new file mode 100644 index 0000000000..cacbe5720a --- /dev/null +++ b/test/Riok.Mapperly.Tests/_snapshots/QueryableProjectionTest.RecordToRecordManualMappingWithGlobalTypeArgsInInliningMappingMethod#Mapper.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: Mapper.g.cs +// +#nullable enable +public partial class Mapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] + public partial global::System.Linq.IQueryable ProjectAToB(global::System.Linq.IQueryable 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 + } +} \ No newline at end of file