You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using System;namespaceConsoleApp4{publicclassCZZZ{staticintcount;staticvoidMain(){
Console.WriteLine(M1());
Console.WriteLine(M2());}publicstaticintM1(){count=0;int_x;return M1_x();intM1_x(){
TryGetX(out _x);if(++count==1){
M1_x();}return_x;}}publicstaticintM2(){int_x;
M2_x();return_x;voidM2_x(){_x=0;}}privatestaticboolTryGetX(outintx){x=count;returntrue;}}}
Actual
M1: InvalidOperationException: Sequence contains no elements, maybe related to #1781
System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at ICSharpCode.Decompiler.IL.Transforms.TransformDisplayClassUsage.IsClosure(ILTransformContext context, ILVariable variable,ITypeDefinition&closureType,ILInstruction&initializer)
at ICSharpCode.Decompiler.IL.Transforms.TransformDisplayClassUsage.Run(ILFunction function, ILTransformContext context)
at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext)
M1: After modified variable.HasInitialValue to variable.AddressCount > 0(which also fix #1781) in TransformDisplayClassUsage.cs, it not throw exception.
For the method M2 I have added a fix to prevent removing the return statement.
@dgrunwald Do you have any idea how we could extend the DeclareVariables step to support correctly declaring variables captured in local functions that do not have any use-sites except the calls to the local function?
Tested with
6.0.0.5559-preview2
Orig Code
Actual
M1
:InvalidOperationException: Sequence contains no elements
, maybe related to #1781M1
: After modifiedvariable.HasInitialValue
tovariable.AddressCount > 0
(which also fix #1781) inTransformDisplayClassUsage.cs
, it not throw exception.ILSpy/ICSharpCode.Decompiler/IL/Transforms/TransformDisplayClassUsage.cs
Line 167 in d8a0882
But the scope of
_x
will be changed, and it will return 0 instead of 1 in new code.M2
: Maybe an variant ofM1
, it will not throwInvalidOperationException
, but will hit some assert and see thereturn
is lost.The text was updated successfully, but these errors were encountered: