-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Add support for VB.NET cached delegate initialization with closures #2844
Add support for VB.NET cached delegate initialization with closures #2844
Conversation
In the latest commit, I fixed support for cached delegate initialization detection using the pattern from Test code: Public Shared Function UseDelegate() As Func(Of Integer)
Dim del As Func(Of Integer) = Function() 2
del(2)
Return del
End Function ILAst before
|
Applied the fix mentioned in the comment above to the newly added |
The latest commit adds support for a rare case of cached delegate initialization generated by the VB compiler when an anonymous method that does not utilize captured variables and is directly returned. VB code: Public Shared Function ReturnDelegate() As Func(Of Integer)
Return Function() 2
End Function IL:
ILAst (before cached delegate initialization transformation):
|
Thank you very much for your contribution! |
Link to issue(s) this covers:
#2199
Problem
The
CachedDelegateInitialization
transform did not fully support VB cached delegate initialization. The pattern emitted when an anonymous function uses a local from a display class/closure was not supported. This can be seen by decompilingClass5.method_0()
from the sample provided in the aforementioned issue report. This can be seen in the code inside the first try region.Before:
After:
Smaller code to reproduce the issue:
Solution
Implement support for the pattern seen in this sample.
A unit test was not added as ILSpy does not currently support VB.NET closures/display classes as they differ in structure from the C# ones. This lack of support makes it impossible to create pretty C# decompilation while testing this pattern.