Remove braces error

Hi,

The remove braces feature is cool yet I've recently discovered that it has mistakes. See the following example code:

            int b = 5;
            int a = 3;

            if (b != 5)
            {
                for (int i = 0; i < 10; i++)
                {
                    if i == 7)
                    {
                        a = 6;
                    }
                }
            }
            else
            {
                a = 4;
            }

            System.Diagnostics.Debug.WriteLine(a);

The path taken is that a is assigned a value of 4.

R# suggests to remove curly brackets on the lines where I have placed the smileys.

If I perform the reformat of code according to the suggestions, R# end with the following code:

            int b = 5;
            int a = 3;

            if (b != 5)
                for (int i = 0; i < 10; i++)
                    if (i == 7)
                        a = 6;
                    else
                        a = 4;

            System.Diagnostics.Debug.WriteLine(a);

Note that the assign of a = 4 is out of sync and occurs when i != 7. Therefore a = 3 in this case.

3 comments

Hello Gidon,

I cannot reproduce it, do you have any additional information about it?

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


IR> Hi,
IR>
IR> The remove braces feature is cool yet I've recently discovered that
IR> it has mistakes. See the following example code:
IR>
IR> int b = 5;
IR> int a = 3;
IR> if (b != 5)
IR> {{emoticon:__jive_emoticon_name=grin}
IR> for (int i = 0; i < 10; i++)
IR> {{emoticon:__jive_emoticon_name=grin}
IR> if (b == 7)
IR> {{emoticon:__jive_emoticon_name=grin}
IR> a = 6;
IR> }
IR> }
IR> }
IR> else
IR> {{emoticon:__jive_emoticon_name=grin}
IR> a = 4;
IR> }
IR> System.Diagnostics.Debug.WriteLine(a);
IR>
IR> The path taken is that a is assigned a value of 4.
IR>
IR> R# suggests to remove curly brackets on the lines where I have
IR> placed the smileys.
IR>
IR> If I perform the reformat of code according to the suggestions, R#
IR> end with the following code:
IR>
IR> int b = 5;
IR> int a = 3;
IR> if (b != 5)
IR> for (int i = 0; i < 10; i++)
IR> if (b == 7)
IR> a = 6;
IR> else
IR> a = 4;
IR> System.Diagnostics.Debug.WriteLine(a);
IR>
IR> Note that the assign of a = 4 is out of sync and occurs when b != 7,
IR> and therefore a = 3.
IR>
IR> ---
IR> Original message URL:
IR> http://www.jetbrains.net/devnet/message/5234527#5234527


0


Sorry, reply to wrong message :(


Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


0

Hello,

We appreciate your feedback. The corresponding JIRA request has been created,
and you are welcome to monitor its status at http://www.jetbrains.net/jira/browse/RSRP-101720.

You may want to check our request tracking policy here: http://www.jetbrains.net/confluence/display/ReSharper/ReSharperIssueTracker

Best regards,
- Development Team.


0

Please sign in to leave a comment.