What's common between C# 4.0 optional parameters, object initializers, the new WPF code editor and the navigation bar comboboxes?

I found an interesting bug recently which resulted from a pretty weird constellation of the following Visual Studio features:

  1. C# 4.0 optional parameters
  2. object initializer syntax
  3. the VS code editor rewritten from scratch in managed code and WPF
  4. the navigation bar combobox updated to show default values for optional parameters

Here's the screenshot of the bug:

image

If you pasted this code in a recent VS 2010 build, the navigation bar (two comboboxes above) would grow to accomodate the full text of the Main method. Why?

Here's what happens:

  1. The code contains a parse error (missing closing parenthesis after new Program())
  2. The IDE parser (which is very resilient) parses the entire Main method body as the object initializer on the default value of Program
  3. Since during the parsing stage we don't apply certain compiler checks yet, the parser assumes that an object creation expression with an object initializer is a valid default value for the optional parameter
  4. it takes the entire text of the parameter (including the default value and the initializer) and passes it to the New Editor for displaying in the navigation bar as part of Main's signature
  5. the New Editor's navbar comboboxes aren't simply textboxes - they are instances of the full-blown WPF New Editor control themselves
  6. since they're so powerful, they have absolutely no problem displaying multiline content
  7. the rest of the WPF layout shifts accordingly to accomodate the growing content

We hope to fix the bug before VS 2010 Beta 2 (probably not Beta1 because it's a low impact low priority).