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: Inlined argument with full namespace #1233

Merged
merged 1 commit into from Apr 14, 2024

Conversation

trejjam
Copy link
Contributor

@trejjam trejjam commented Apr 11, 2024

The inlined method does not resolve arguments full namespace

Description

The following mapping produces an invalid code:

private partial System.Linq.IQueryable<B> Map(System.Linq.IQueryable<A> source);

private static DateTimeOffset MapToDateTimeOffset(
    DateTime dateTime
) => new(dateTime, TimeSpan.Zero);

The argument was kept as-is, therefore, without namespace or using statements.

Before:

[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
private partial global::System.Linq.IQueryable<global::B> Map(global::System.Linq.IQueryable<global::A> source)
{
#nullable disable
    return System.Linq.Queryable.Select(source, x => new global::B()
    {
        Value = new(x.Value, TimeSpan.Zero),
    });
#nullable enable
}

Expected:

[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")]
private partial global::System.Linq.IQueryable<global::B> Map(global::System.Linq.IQueryable<global::A> source)
{
#nullable disable
    return System.Linq.Queryable.Select(source, x => new global::B()
    {
        Value = new(x.Value, global::System.TimeSpan.Zero),
    });
#nullable enable
}

Checklist

  • The existing code style is followed
  • The commit message follows our guidelines
  • Performed a self-review of my code
  • Hard-to-understand areas of my code are commented
  • The documentation is updated (as applicable)
  • Unit tests are added/updated
  • Integration tests are added/updated (as applicable, especially if feature/bug depends on roslyn or framework version in use)

Copy link
Contributor

@latonz latonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this Fix 😊

While looking at your example, I came up with the idea that we should also extend Target-Type new. I'm not sure if it really causes problems, but since the compilation context changes quite a bit by inlining these expressions it should be safer to just expand them... WDYT? (If we decide to fix this we should do it in another PR 😊)

src/Riok.Mapperly/Descriptors/InlineExpressionRewriter.cs Outdated Show resolved Hide resolved
@latonz latonz merged commit de3b332 into riok:main Apr 14, 2024
17 checks passed
@latonz
Copy link
Contributor

latonz commented Apr 14, 2024

Created a fix for the implicit new in #1238

Copy link

🎉 This PR is included in version 3.5.1-next.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@trejjam trejjam deleted the fix/inlined-methods branch April 15, 2024 15:16
Copy link

🎉 This PR is included in version 3.5.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants