-
-
Notifications
You must be signed in to change notification settings - Fork 196
feat: support ref keyword in user defined methods for the target parameter #1895
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
Conversation
8ba3ff6
to
3146755
Compare
Thank you for this contribution, whats the reason for introducing the temporary field in the generated code? |
If the member access is a property, you can not pass it as a reference. Since it's really a function call. So it need to take the reference and then assign it back. var a = new ClassWithProperty();
// this
FunctionWithRefParam(ref a.Property);
// becomes this (kind of)
FunctionWithRefParam(ref a.get_Property()); |
There was a problem hiding this 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 😊 I added my feedback.
src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.Invocation.cs
Outdated
Show resolved
Hide resolved
...iok.Mapperly/Descriptors/Mappings/UserMappings/UserImplementedExistingTargetMethodMapping.cs
Outdated
Show resolved
Hide resolved
...iok.Mapperly/Descriptors/Mappings/UserMappings/UserImplementedExistingTargetMethodMapping.cs
Show resolved
Hide resolved
5a91078
to
423c6e3
Compare
I've also rebased on latest |
...iok.Mapperly/Descriptors/Mappings/UserMappings/UserImplementedExistingTargetMethodMapping.cs
Outdated
Show resolved
Hide resolved
test/Riok.Mapperly.IntegrationTests/UseUserMethodWithRefTest.cs
Outdated
Show resolved
Hide resolved
423c6e3
to
1a7d7ed
Compare
That last failing test, I hope it's fixed now, but no idea why it broke for .NET 4.8. |
The tests are failing due to the non-nullable not initialized array field in the integration tests: https://github.com/riok/mapperly/actions/runs/16592052238/job/46930700287?pr=1895#step:4:22 The integration test for the .net framework is failing since we generate slightly different code for the .net framework. Instead of |
aacdb38
to
2436787
Compare
Alright that should then fix it, I mirrored the nullable annotation from |
2436787
to
52c965a
Compare
I understand the issue now, it needs both snapshots. |
Thank you for this great contribution! 🥳 |
support ref keyword in user defined methods for the target parameter
Description
This will emit a ref keyword and supporting lines so pass by value types can actually be updated by the existing target methods (immutable records, array etc.) when the user defined methods has a ref keyword.
Fixes #1892
Checklist
This is an initial attempt at solving this issue, does this agree with how the project would expect solving this issue?I has to extend the
MethodParameter
struct and pass it down a bit further to get the extra required context to the point where the Arguments are made. Not sure if there is some clean up that is possible to unify some of the other code paths.