New warning in 5.1 "Type parameter 'T' hides class 'T'" confusing

Since updating to ReSharper 5.1, I have discovered quite a few new warnings in files that were previously clean.  I have already downgraded to a suggestion the one that reports almost any foreach() loop can be made a Linq expression, as I feel it often results in less readable code.  There are some new warnings I will fix, though.

But, one currently has me stumped.  On a generic function like:

        protected static T ShowDialog<T>(Action act) where T : Form
        {
            ...
        }

ReSharper now underlines the T in the angle-brackets, i.e. <T>, and reports "Type parameter 'T' hides class 'T'".  If I use Alt+Enter to review the possible resolutions to this issue, ReSharper suggest only to suppress this warning with a #pragma.  No other way to disable the warning at all.  Ack!

I have no idea what class ReSharper is referring to.  If I try "new T()" in another non-generic function in the same class, Resharper reports "Cannot access internal class 'T' here".  If I change the generic name T to TForm, this fixes the problem, but T is my usual generic default for only one type.  This gets used in programming books on the subject for multiple languages.

Couldn't we please have T back?  Or is there really something simple I am just missing completely that will allow me to get rid of all these warnings without renaming all my type parameters.

Love the software, though.  It has made moving from Java and IntelliJ positively enjoyable.  Thanks for the worldclass tools!

5 comments
Comment actions Permalink

Hello,

It looks like containing type is generic:

class A http://devnet.jetbrains.net/message/5275617#5275617


0
Comment actions Permalink

In the case I sent, the class definition is:

    public abstract class AbstractFunctionalTest
    {
    ...
    }

I get the same message on every generic class of function I have looked at in my project that uses T.

0
Comment actions Permalink

Please could you provide the text of this file (Without method bodies, it is OK - only class/method metadata is interesting)

0
Comment actions Permalink

Hi Eugene,
Okay I started a brand new project, and have had no issues with creating generic classes and functions using T.  So, clearly it is not something about T itself, but more likely something about my project, though the warning is giving me very little help in figuring out what that issue might by.  The warning was not present before I upgraded to 5.1 from the 4.5 line.  But, now any generic, no matter how simple that attempts to use T in my project gives me this warning.  I just tried:

    internal class Generic<T>
    {        
    }

And the T gets underlined, with this warning attached.

My project is open source:

http://sourceforge.net/projects/proteowizard/develop

Once it is checked out, the project showing this issue is under <pwiz_root>/pwiz/pwiz_tools/Skyline/Skyline.sln

You can pretty much search for <T>, and you should find a good set of generic code with this warning.

I am guessing this is the easiest way for you to debug this problem, as it could take me a very long time to figure out what combination of classes and functions cause this in a simplified project.

--Brendan

0
Comment actions Permalink

Ok, I've investigated what happens.

The key is that assembly  DigitalRune.Windows.Docking contains internal class "T", which cause ReSharper to think about name conflict. But this class is internal, and thus not accessible in the point of possible conflict (i.t. in the type parameter declartion). I've fixed the ReSharper analysis in the ReSharper v6.0

0

Please sign in to leave a comment.