Skip to content

Commit

Permalink
Fix missing global alias on method argument in inlined user-implement…
Browse files Browse the repository at this point in the history
…ed method #1629 (#1630)
  • Loading branch information
TonEnfer authored Dec 8, 2024
1 parent d94ad8c commit 84e374d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
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
}
}

0 comments on commit 84e374d

Please sign in to comment.