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

Fix or support return ref value #415

Open
Tracked by #417
quifi opened this issue Jun 18, 2024 · 4 comments
Open
Tracked by #417

Fix or support return ref value #415

quifi opened this issue Jun 18, 2024 · 4 comments
Assignees
Labels

Comments

@quifi
Copy link

quifi commented Jun 18, 2024

With C#, we can return a ref value:

ref Int32 ReturnByRef(ref Int32 x) => ref x;

System expression simply says it is not supported

System.ArgumentException : Expression of type 'System.Int32' cannot be used for return type 'System.Int32&'

LightExpression supports return ref value, but sometimes fails to unref returned ref value.
e.g.

Int32 f(ref Int32 x) => ReturnByRef(ref x);

emits

ldarg.1
call Int32& ReturnRef(Int32 ByRef)
(missing ldind.i4)
ret

See the "ReadReturnedRef" test case of attached source file.
ReturnRef.zip

I tried to add a EmitLoadIndirectlyByRef after each Demit(OpCodes.Call), which seemed worked.

@dadhi
Copy link
Owner

dadhi commented Jun 19, 2024

@quifi Thank you for the reporting and for the 2 other issues

dadhi added a commit that referenced this issue Jun 26, 2024
@dadhi
Copy link
Owner

dadhi commented Jun 26, 2024

@quifi I have checked your sample, but I don't see ldind.i4 in the decompiled IL code

So the current FEC output is fine, I think.

dadhi added a commit that referenced this issue Jun 26, 2024
dadhi added a commit that referenced this issue Jul 2, 2024
@dadhi dadhi closed this as completed in 2f88a17 Jul 2, 2024
dadhi added a commit that referenced this issue Jul 2, 2024
@dadhi dadhi self-assigned this Jul 2, 2024
@dadhi dadhi added this to the v4.2.1 milestone Jul 2, 2024
@dadhi dadhi added the bug label Jul 2, 2024
@dadhi
Copy link
Owner

dadhi commented Jul 2, 2024

@quifi The new FEC v4.2.1 with the fixes is released.

@quifi
Copy link
Author

quifi commented Jul 5, 2024

FEC

In order to reproduce the bug, I think 'Bar' should return int, instead of int&.
See modified sample code

With v4.2.1, this one seems not fixed yet.

@dadhi dadhi reopened this Jul 8, 2024
@dadhi dadhi modified the milestones: v4.2.1, v4.2.2 Jul 8, 2024
@dadhi dadhi modified the milestones: v4.2.2, v4.3.0 Oct 13, 2024
@dadhi dadhi removed this from the v4.3.0 milestone Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants