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

feat: generate generic mapping only with LSP compatible methods #1000

Merged
merged 5 commits into from
Dec 14, 2023

Conversation

trejjam
Copy link
Contributor

@trejjam trejjam commented Dec 12, 2023

Generate generic mapping only with LSP compatible methods

Description

Generic mapping is selecting target methods only by type argument constraint. This PR filters them also by LSP type compatibility.

Right now, the mapping does not produce valid code when e.g. source is a specific abstract type (not the object). And your mapper has e.g. enum mapping. The compiler then complains: Error CS8121 : An expression of type 'TheClass' cannot be handled by a pattern of type 'TheEnum'. on generated code that looks like this:

partial T Map<T>(TheClass source)
{
    return source switch
            {
                global::TheEnum x when typeof(T).IsAssignableFrom(typeof(global::TheEnum)) => (T)(object)MapToTheEnum(x),
            };
}

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

codecov bot commented Dec 12, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0aa8b0b) 91.40% compared to head (e18f6d8) 91.40%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1000   +/-   ##
=======================================
  Coverage   91.40%   91.40%           
=======================================
  Files         223      223           
  Lines        7256     7259    +3     
  Branches      911      913    +2     
=======================================
+ Hits         6632     6635    +3     
  Misses        412      412           
  Partials      212      212           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@trejjam trejjam force-pushed the feature/type-constraint-generic-mapping branch 5 times, most recently from c37aea2 to cec5e00 Compare December 13, 2023 10:23
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 contribution 😊

@trejjam trejjam force-pushed the feature/type-constraint-generic-mapping branch from 3a77938 to e18f6d8 Compare December 13, 2023 21:15
@trejjam trejjam requested a review from latonz December 13, 2023 21:52
@latonz latonz enabled auto-merge (squash) December 14, 2023 03:51
@latonz latonz merged commit 9a2916f into riok:main Dec 14, 2023
Copy link

🎉 This PR is included in version 3.3.1-next.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link

🎉 This PR is included in version 3.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@trejjam trejjam deleted the feature/type-constraint-generic-mapping branch July 26, 2024 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants