Quantcast
Channel: YouTrackReSharper (RSRP) - Bug and Issue Tracker
Viewing all articles
Browse latest Browse all 106942

RSRP-289038: Wrong unreachable code refactoring for "do {...} while(false)"

$
0
0
Reporter Tomas Kovarik (Tomas.Kovarik) Tomas Kovarik (Tomas.Kovarik)
Created Mar 5, 2012 9:12:21 PM
Updated Mar 5, 2012 9:13:51 PM
Priority Normal
Type Unspecified
Fix versions No Fix versions
State Submitted
Assignee Sergey Shkredov (serjic.shkredov)
Subsystem Refactoring
Affected versions 6.1
Fixed in build No Fixed in build
I often use do { some code } while (false) in my code in cases, when a failover value is expensive to create. If something wrong happens during computing of real value, I use "break" to jump out of the block and create and return failover value. See the example below. Resharper (correctly) identifies the "while (false)" as unreachable code and offers refactoring to remove it. But by removing the "while" block I cannot use "break" to jump out of it, so it is not compilable. In this cases resharper should not offer the refactoring.

Example
public class A
{
public bool Initialized { get; private set; }

public static A CreateA(int value)
{
do
{
// Some code ....
// Some condition check
if (value == 0) { break; }
// Some code ....
// Some condition check
if (value == 1) { break; }
// Some code ....
// Some condition check
if (value == 2) { break; }

// Return initialized value
return new A { Initialized = true };
} while (false);

// Return default value
return new A();
}
}

Viewing all articles
Browse latest Browse all 106942

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>