Repository navigation
Conversation
Static interface methods discovered as user-implemented mappings were invoked through a cast instance, e.g. ((global::IMapperBase)this).MapValue(x), which does not compile (CS0176, CS0026 in static mapping methods, CS0119 for static external mappers). Invoke them on the interface type instead: global::IMapperBase.MapValue(x).
Static abstract and static virtual interface members can only be accessed through a type parameter (CS8926), so they cannot be used as user-implemented mappings. Ignore them, reporting RMG001 if they are marked with UserMappingAttribute.
A method marked with [UserMapping(Ignore = true)] is now skipped even if its signature is unsupported, e.g. a static abstract interface member, instead of reporting RMG001.
Contributor
Author
|
This is a niche issue. I didn't find it in my code. An agent did while I was working on the #2240 . I did not find it super important; if you do not want to spend time on it, just close it. I reviewed the code, and it seems correct. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: invoke static interface mapping methods on the interface type
Description
When a mapper (or an external mapper used via
[UseMapper]/[UseStaticMapper]) implements an interface that declares a static method, Mapperly picks the method up as a user-implemented mapping. It then calls it through a cast instance, which does not compile:The same cast was emitted for existing-target (
void) mappings, non-inlinable queryable projections,static partialmapping methods (CS0026,thisin a static method),[UseMapper]members (CS0176) and[UseStaticMapper]types (CS0119,((global::IOther)global::Other)).Four commits:
fix: invoke static interface mapping methods on the interface type:UserImplementedMethodMappingandUserImplementedExistingTargetMethodMappingcall static interface methods on the fully qualified interface type instead of casting the receiver. Output for all other mappings is unchanged.fix: ignore static abstract and static virtual interface mapping methods: these members can only be accessed through a type parameter (CS8926), soglobal::IBaseMapper<global::Mapper>.BaseMapping(...)does not compile either.UserMethodMappingExtractornow treats them as invalid user mappings: ignored, or RMG001 when marked with[UserMapping](unlessIgnore = true). An implicit implementation in the mapper (public static D BaseMapping(C source)) is still discovered and used as before.fix: honor ignored user mappings before reporting unsupported signatures: a method marked with[UserMapping(Ignore = true)]is skipped before its signature is validated, so an ignored static abstract member (or any other ignored method with an unsupported signature) no longer reports RMG001.docs: document user-implemented mapping methods in base classes and interfaces: adds a short section to the user-implemented methods docs.The change is covered by unit tests that assert the generated code. No integration tests were added.
Checklist