Skip to content

fix: fully qualify explicit lambda return types in inlined expressions - #2499

Merged
latonz merged 1 commit into
riok:mainfrom
trejjam:feature/inline-lambda-return-type
Nov 21, 2026
Merged

latonz merged 1 commit into
riok:mainfrom
trejjam:feature/inline-lambda-return-type

Conversation

@trejjam

@trejjam trejjam commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

fix: fully qualify explicit lambda return types in inlined expressions

Description

A lambda with an explicit return type inside a user-implemented mapping method kept that type as written when Mapperly inlined the method into a queryable projection. The generated code has no using directives, so a type like DateTime? did not resolve and the generated mapper failed to compile.

Mapperly now writes the return type with its full name, the same as other type names in an inlined expression. Nullable annotations are preserved, including on reference types and type arguments.

Source:

private DateTime? LastCreated(List<C> v)
    => v.Select(DateTime? (x) => x.DateCreated).Max();

Before:

Created = global::System.Linq.Enumerable.Max(global::System.Linq.Enumerable.Select(x.Created, DateTime? (x1) => x1.DateCreated)),

After:

Created = global::System.Linq.Enumerable.Max(global::System.Linq.Enumerable.Select(x.Created, global::System.DateTime? (x1) => x1.DateCreated)),

No related issue.

Checklist

  • I did not use AI tools to generate this PR, or I have manually verified that the code is correct, optimal, and follows the project guidelines and architecture
  • I understand that low-quality, AI-generated PRs will be closed immediately without further explanation
  • 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)

A lambda with an explicit return type, such as
`.Select(DateTime? (x) => x.DateCreated)`, kept its return type as written
when the user-implemented mapping was inlined into a projection. The
generated code has no usings, so the type did not resolve.

Co-Authored-By: Claude <noreply@anthropic.com>
@latonz latonz self-assigned this Nov 20, 2026
@latonz latonz added the bug Something isn't working label Nov 20, 2026

@latonz latonz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this contribution, I added my feedback.

@latonz
latonz merged commit 44a7b9d into riok:main Nov 21, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants