Remove Warning

I like the new "errors gutter" (although I can't figure out placement of the
colored bars) and I've been cruising my code to see what it finds (quite a
bit actually). I did run into a warning that I can't seem to eliminate. I
have a unit test (called by NUnit) similar to:



public void IndexerTestNegative()
{
String junk = myCustomCollection[-1].MyProperty ; *** WARNING
***
Assert.Fail( ) ;
}

The warning is "Local variable 'junk' is declared but never used". However,
I can't seem to do anything to get rid of the warning. Are there any code
tricks to remove this? It's not a big deal - I'm just being anal about no
warnings in the code.

Thanks in advance!

--
Derek Price


2 comments
Comment actions Permalink

Derek,

"Derek Price" <dprice@doble.com> wrote in message
news:c66me7$dm9$1@is.intellij.net...

I like the new "errors gutter" (although I can't figure out placement of

the

colored bars) and I've been cruising my code to see what it finds (quite a
bit actually).


Errors gutter is now really not very usable, but in the nearest future
you'll be able to navigate to
errors and warnings by clicking on a colored bar. It will also show
tool-tips when mouse hovers
over a colored bar.

I did run into a warning that I can't seem to eliminate. I
have a unit test (called by NUnit) similar to:

>



public void IndexerTestNegative()
{
String junk = myCustomCollection[-1].MyProperty ; *** WARNING
***
Assert.Fail( ) ;
}

>

The warning is "Local variable 'junk' is declared but never used".

However,

I can't seem to do anything to get rid of the warning. Are there any code
tricks to remove this? It's not a big deal - I'm just being anal about no
warnings in the code.

>

Thanks in advance!

>

The warning is correct in a sense that 'junk' variable is not used in your
code. However,
removal of this variable along with its initializer will change the behavior
of the program. So, in
order to get rid of this warning you need to rewrite this code in such a way
that it does not
declare unused variable. E.g. you can write



public void IndexerTestNegative()
{
if (myCustomCollection[-1].MyProperty == null) {}
Assert.Fail( ) ;
}

instead. I think that this will serve the purpose of generating
IndexOutOfBounds at the same time
causing no warning.


0
Comment actions Permalink

That worked - Thanks!
Derek

On 22 Apr 2004 04:04, "Dmitry Shaporenkov \(JetBrains\)" <dsha@jetbrains.com>
wrote:
>The warning is correct in a sense that 'junk' variable is not used in
>your code. However, removal of this variable along with its initializer
>will change the behavior of the program. So, in order to get rid of
>this warning you need to rewrite this code in such a way that it does
>not declare unused variable. E.g. you can write
>



public void IndexerTestNegative()
{
if (myCustomCollection[-1].MyProperty == null) {}
Assert.Fail( ) ;
}

>
>instead. I think that this will serve the purpose of generating
>IndexOutOfBounds at the same time causing no warning.



0

Please sign in to leave a comment.