[Math] Relax constraints on arguments passed as ref across math types by Eideren · Pull Request #2044 · stride3d/stride (original) (raw)
PR Details
See title, this enables arguments passed as in
to be passed into those functions without copying.
Has a side effect of allowing users to pass their variables without specifying in
or ref
modifier, dotnet will produce a warning instead of syntax error.
Example:
void F0(ref readonly int i){}
F0(124); // warning: Argument 1 should be a variable because it is passed to a 'ref readonly' parameter int i = 124; F0(in i); // OK F0(ref i); // OK
void F1(in int i) => F0(in i); // OK void F2(ref int i) => F0(in i); // OK void F3(ref readonly int i) => F2(ref i); // Error, F2 is not readonly void F3(in int i) => F2(ref i); // Error, F2 is not readonly
See ref readonly
feature specification https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-12.0/ref-readonly-parameters
Related Issue
None
Motivation and Context
Prevents a forced copy for passing structs that are received as in
Types of changes
- Docs change / refactoring / dependency upgrade
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing functionality to change)
Checklist
- My change requires a change to the documentation.
- I have added tests to cover my changes.
- All new and existing tests passed.
- I have built and run the editor to try this change out.