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:
- C# 4.0 optional parameters
- object initializer syntax
- the VS code editor rewritten from scratch in managed code and WPF
- the navigation bar combobox updated to show default values for optional parameters
Here's the screenshot of the bug:
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:
- The code contains a parse error (missing closing parenthesis after new Program())
- The IDE parser (which is very resilient) parses the entire Main method body as the object initializer on the default value of Program
- 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
- 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
- the New Editor's navbar comboboxes aren't simply textboxes - they are instances of the full-blown WPF New Editor control themselves
- since they're so powerful, they have absolutely no problem displaying multiline content
- 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).