Wrong analysis: "never accessed"

FYI,
in the following snippet :
...
string localDateNais = dateNaissance;
if (DateTime.TryParse(dateNaissance, out localDateTime)) {
....
}

Resharper gives 'Local variable 'localDateNais' is assigned but never
accessed.





3 comments
Comment actions Permalink

FYI,
in the following snippet :
...
string localDateNais = dateNaissance;
if (DateTime.TryParse(dateNaissance, out localDateTime)) {
....
}
Resharper gives 'Local variable 'localDateNais' is assigned but never
accessed.

And what is wrong with the message?

Thanks,
Andrey Simanovsky


0
Comment actions Permalink

Andrey Simanovsky (JetBrains) wrote:
>> FYI,
>> in the following snippet :
>> ...
>> string localDateNais = dateNaissance;
>> if (DateTime.TryParse(dateNaissance, out localDateTime)) {
>> ....
>> }
>> Resharper gives 'Local variable 'localDateNais' is assigned but never
>> accessed.

And what is wrong with the message?

>>

Thanks,
Andrey Simanovsky


If it's used to test if it CanParse (but not actually parse and store
somewhere) you'll still have to provide the out parameter regardless. So
unless there's a dummy variable somewhere you can pass in, this is an
obligatory "never assigned variable" that can easily be detected (just
filter all mark TryParse functions as read&write.

Jesse

0
Comment actions Permalink

Hello Jesse,

not sure I completely understand what you mean, but the variable
'localDateNais' of the 'string' type is really not accessed in the posted
code sample (if, of course,
it is not accessed further in the rest of the method which is omitted). It
seems you're talking
about 'localDateTime' variable of the 'DateTime' type, but this is a different
variable.


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

Andrey Simanovsky (JetBrains) wrote:

>>> FYI,
>>> in the following snippet :
>>> ...
>>> string localDateNais = dateNaissance;
>>> if (DateTime.TryParse(dateNaissance, out localDateTime)) {
>>> ....
>>> }
>>> Resharper gives 'Local variable 'localDateNais' is assigned but
>>> never
>>> accessed.
>> And what is wrong with the message?
>>
>> Thanks,
>> Andrey Simanovsky

If it's used to test if it CanParse (but not actually parse and store
somewhere) you'll still have to provide the out parameter regardless.
So unless there's a dummy variable somewhere you can pass in, this is
an obligatory "never assigned variable" that can easily be detected
(just filter all mark TryParse functions as read&write.

Jesse



0

Please sign in to leave a comment.