[233] Mixup of local variables and types when using static members

Hi,

Resharper produces wrong error messages with the following code :


public class Singleton
{
private static Singleton singleton= new Singleton();

private Singleton()
{
}

public static Singleton Instance
{
get
{
return Singleton.singleton;
}
}
}

public class Client
{
public void Foo()
{
Singleton Singleton= Singleton.Instance; // Resharper reports errors, because local variable and type are mixed up
}

public void Foo2()
{
Singleton Singleton2= Singleton.Instance; // ok
}
}




Regards,
Uwe

0
3 comments
Avatar
Permanently deleted user

Hi Uwe,

Why shouldn't it report errors in the situation you describe? I expect it would.

Thanks,
Craig

0
Avatar
Permanently deleted user

Hi Craig,

just because it is not an error. The compiler can determine from the context whether 'Singleton' is the local variable or the type.

Regards,
Uwe

0
Avatar
Permanently deleted user

Hi Uwe,

I added a tracker request for that:
http://www.intellij.net/tracker/resharper/viewSCR?publicId=22363

It will be great if next time you do this yourself. The problem will be
easier to track for both you and me.

Friendly,
Dmitry
Uwe Hammermeister wrote:

Hi,

Resharper produces wrong error messages with the following code :


public class Singleton
{
private static Singleton singleton= new Singleton();

private Singleton()
{
}

public static Singleton Instance
{
get
{
return Singleton.singleton;
}
}
}

public class Client
{
public void Foo()
{
Singleton Singleton= Singleton.Instance; // Resharper reports errors, because local variable and type are mixed up
}

public void Foo2()
{
Singleton Singleton2= Singleton.Instance; // ok
}
}




Regards,
Uwe



--
Dmitry Lomov
Senior Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop With Pleasure!"

0

Please sign in to leave a comment.