I suggest you ...

Use of unassigned local variable

If a Boolean is guarding both the initialization and use of a local variable, VS should attempt to recognize that. There are other similar circumstances that have been introduced to VS recently.

This actually leads to improved code. Forcing a var to be initialized even when it ultimately won't be used ends up blocking VS's ability to alert the developer when the var really is being used when it shouldn't.

Example:

public int Test(bool flag)
{
int value;
if (flag) value = 0;
int result = 0;
if (flag) result = value + 1;
return result;
}

"value" should not be flagged as unassigned since "flag" is preventing it from being used in an unassigned state. If "value" is assigned on the declaration for no other reason than to avoid the error, it causes VS to be unable to detect when "value" may actually be used without having been guarded. Changing this behavior allows the developer to intentionally leave "value" unassigned when it isn't supposed to be used, and thus allowing VS to issue the error when it legitimately does end up being used by accident when it wasn't supposed to be.

1 vote
Vote
Sign in
(thinking…)
Password icon
Signed in as (Sign out)
You have left! (?) (thinking…)
Keith Burgoyne shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

0 comments

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...

Feedback and Knowledge Base