ILSpy icon indicating copy to clipboard operation
ILSpy copied to clipboard

LocalFunctionDecompiler misplaces nested local functions in ctors

Open greenozon opened this issue 4 years ago • 1 comments

Steps to reproduce

  1. get input https://www.sendspace.com/file/iru3ns
  2. decompile
  3. observe error below

Error message shown

Error decompiling @06000D7A Microsoft.CodeAnalysis.EditAndContinue.EditAndContinueDiagnosticDescriptors..cctor
in assembly "C:\temp\err104.dll"
 ---> ICSharpCode.ILSpy.AssertionFailedException: 
   at ICSharpCode.ILSpy.ILSpyTraceListener.Fail(String message, String detailMessage) in offset 380
   at ICSharpCode.ILSpy.ILSpyTraceListener.Fail(String message) in offset 9
   at System.Diagnostics.TraceInternal.Fail(String message) in offset 55
   at System.Diagnostics.Debug.Assert(Boolean condition) in offset 6
   at ICSharpCode.Decompiler.CSharp.CallBuilder.Build(OpCode callOpCode, IMethod method, IReadOnlyList`1 callArguments, IReadOnlyList`1 argumentToParameterMap, IType constrainedTo) in offset 175
   at ICSharpCode.Decompiler.CSharp.CallBuilder.Build(CallInstruction inst) in offset 418
   at ICSharpCode.Decompiler.CSharp.ExpressionBuilder.VisitCall(Call inst, TranslationContext context) in offset 29
   at ICSharpCode.Decompiler.IL.Call.AcceptVisitor[C,T](ILVisitor`2 visitor, C context) in offset 9
   at ICSharpCode.Decompiler.CSharp.ExpressionBuilder.Translate(ILInstruction inst, IType typeHint) in offset 61
   at ICSharpCode.Decompiler.CSharp.StatementBuilder.Default(ILInstruction inst) in offset 14
   at ICSharpCode.Decompiler.IL.ILVisitor`1.VisitCall(Call inst) in offset 1
   at ICSharpCode.Decompiler.IL.Call.AcceptVisitor[T](ILVisitor`1 visitor) in offset 1
   at ICSharpCode.Decompiler.CSharp.StatementBuilder.Convert(ILInstruction inst) in offset 16
   at ICSharpCode.Decompiler.CSharp.StatementBuilder.ConvertBlockContainer(BlockStatement blockStatement, BlockContainer container, IEnumerable`1 blocks, Boolean isLoop) in offset 157
   at ICSharpCode.Decompiler.CSharp.StatementBuilder.ConvertBlockContainer(BlockContainer container, Boolean isLoop) in offset 7
   at ICSharpCode.Decompiler.CSharp.StatementBuilder.VisitBlockContainer(BlockContainer container) in offset 181
   at ICSharpCode.Decompiler.IL.BlockContainer.AcceptVisitor[T](ILVisitor`1 visitor) in offset 1
   at ICSharpCode.Decompiler.CSharp.StatementBuilder.Convert(ILInstruction inst) in offset 16
   at ICSharpCode.Decompiler.CSharp.StatementBuilder.ConvertAsBlock(ILInstruction inst) in offset 1
   at ICSharpCode.Decompiler.CSharp.StatementBuilder.<DeclareLocalFunctions>g__TranslateFunction|59_0(ILFunction function) in offset 102
   at ICSharpCode.Decompiler.CSharp.StatementBuilder.DeclareLocalFunctions(ILFunction currentFunction, BlockContainer container, BlockStatement blockStatement) in offset 78
   at ICSharpCode.Decompiler.CSharp.StatementBuilder.ConvertBlockContainer(BlockContainer container, Boolean isLoop) in offset 35
   at ICSharpCode.Decompiler.CSharp.StatementBuilder.VisitBlockContainer(BlockContainer container) in offset 181
   at ICSharpCode.Decompiler.IL.BlockContainer.AcceptVisitor[T](ILVisitor`1 visitor) in offset 1
   at ICSharpCode.Decompiler.CSharp.StatementBuilder.Convert(ILInstruction inst) in offset 16
   at ICSharpCode.Decompiler.CSharp.StatementBuilder.ConvertAsBlock(ILInstruction inst) in offset 1
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 734
-- continuing with outer exception (ICSharpCode.Decompiler.DecompilerException) --
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 930
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(IMethod method, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 253
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(ITypeDefinition typeDef, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 856
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompileTypes(IEnumerable`1 types, DecompileRun decompileRun, ITypeResolveContext decompilationContext, SyntaxTree syntaxTree) in offset 219
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileTypes(IEnumerable`1 types) in offset 217
   at ICSharpCode.Decompiler.CSharp.ProjectDecompiler.WholeProjectDecompiler.<>c__DisplayClass45_0.<WriteCodeFilesInProject>b__2(IGrouping`2 file) in offset 69
   at System.Threading.Tasks.Parallel.<>c__DisplayClass42_0`2.<PartitionerForEachWorker>b__1() in offset 713
   at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask) in offset 6
   at System.Threading.Tasks.Task.<>c__DisplayClass176_0.<ExecuteSelfReplicating>b__0(Object <p0>) in offset 134

Details

  • Product in use: ILSpy version 7.0.0.6286-preview2

greenozon avatar Jan 09 '21 10:01 greenozon

Retested on latest uptodate ILSpy version 7.0.0.6311-preview2 Issue not reproduced if selected language is C#5.0 but reproduced on the C# 7.3

greenozon avatar Feb 05 '21 07:02 greenozon