Auto-close curly brace bug

I'm not sure if this is a ReSharper problem or a VisualStudio error but I'll try here first.


On line 3, I typed an opening curly brace just after the '(true)'. A closing curly brace was automatically placed at the end of the line which incorrectly includes the 'i++' as part of the if statement.

It appears the closing curly brace is always placed at the end of the line regardless of how many statements are on that line.

My apologies if this isn't a ReSharper issue.

-paul

6 comments
Comment actions Permalink

Here's a case where it works:


When I type a curly brace just after the conditional the closing brace is correctly placed prior to the 'else'.

-paul

0
Comment actions Permalink

This behavour is by design.
ReSharper thinks that in line
if (true) i = 1; i++;
both statements are going to be embraced

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Paul Moore" <no_mail@jetbrains.com> wrote in message
news:1446346.1113854293733.JavaMail.itn@is.intellij.net...

I'm not sure if this is a ReSharper problem or a VisualStudio error but

I'll try here first.
>

 1  private bool Foo() {
> 2    int i = 0;
> 3    if (true) i = 1; i++;
> 4  }
> ]]>

>

On line 3, I typed an opening curly brace just after the '(true)'. A

closing curly brace was automatically placed at the end of the line which
incorrectly includes the 'i++' as part of the if statement.
>

It appears the closing curly brace is always placed at the end of the line

regardless of how many statements are on that line.
>

My apologies if this isn't a ReSharper issue.

>

-paul



0
Comment actions Permalink

This is actually an arguable issue what behavior is better. We should decide
what the user's intention likely is in this situation. How did you come to
such 2 statements on the same line?

Valentin Kipiatkov
Chief Scientist, Vice President of Product Development
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

This behavour is by design.
ReSharper thinks that in line
if (true) i = 1; i++;
both statements are going to be embraced




0
Comment actions Permalink

How did you come to
such 2 statements on the same line?


Legacy Code™

I've been cleaning up some old code and came across both of these situations yesterday. I would like to say there are tests that would have caught the problem but there aren't so I have to be more diligent than usual when cleaning up.

Since there aren't tests I would argue in favor of preserving compiled behavior, so that

would become


To do otherwise could introduce some subtle changes to the compiled app.

By placing the braces where they preserve behavior it becomes pretty obvious that something strange is going on with the code's layout.

-paul

0
Comment actions Permalink

Legacy code in C#? LOL! :)

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Paul Moore" <no_mail@jetbrains.com> wrote in message
news:6688020.1113925679181.JavaMail.itn@is.intellij.net...

How did you come to
such 2 statements on the same line?

>

Legacy Code?

>

I've been cleaning up some old code and came across both of these

situations yesterday. I would like to say there are tests that would have
caught the problem but there aren't so I have to be more diligent than usual
when cleaning up.
>

Since there aren't tests I would argue in favor of preserving compiled

behavior, so that

   if (true) i = 1; i++;
> ]]>

would become

   if (true) { i = 1; } i++;
> ]]>

>

To do otherwise could introduce some subtle changes to the compiled app.

>

By placing the braces where they preserve behavior it becomes pretty

obvious that something strange is going on with the code's layout.
>

-paul



0
Comment actions Permalink

Eugene Pasynkov (JetBrains) wrote:

Legacy code in C#? LOL! :)


Yeah, all the crappy C# 1.0 code created by the old .NET veterans in
VS2002... They should have retired before the VS2005 CTP beta came out
but they're still trying to keep it up. Futile attempts ofcourse. ;)

0

Please sign in to leave a comment.