4
Vote

Stack overflow when adding outer closures

description

I've run into a stack overflow bug when decompiling with the DecompilerOptions.AnonymousDelegates.

The problem occurs when there's an anonymous delegate in a partial class that contributes to a class automatically generated using the Settings Designer (and probably other automatically generated classes as well).

Here's a small repro:
partial class FooSettings
{
   private FooSettings()
   {
     var app = Application.Current;

     if (app != null)
     {
        app.Exit += (sender, e) =>
        {
           Debug.Print("Goodbye world!");
        };
     }
   }
}
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]    
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
public sealed partial class FooSettings
{
   private static FooSettings singleton = new FooSettings();
}
The situation causes the AddOuterClosures method in Closure Finder to recurse indefinitely.

comments

tomenglert wrote Oct 3, 2015 at 9:25 AM

Looks like this is the same issue as in code contracts https://github.com/Microsoft/CodeContracts/issues/169