Seems that R# sometimes doesn't resolve type parameters of generic classes

It seems that R# doesn't resolve type parameters of generic classes if a method of generic class contains a local variable of the same generic type but with different type parameters. R# highlights some expressions in my code as errors (see attachments with screenshots and code samples) but VS compiles them successfully. It's a bug, isn't it?



Attachment(s):
overload.GIF
map.gif
overload.cs
map.cs
0
8 comments
Avatar
Permanently deleted user

OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
VS 2005 version 8.0.50727.51
ReSharper build 251

0
Avatar
Permanently deleted user

Hello Vladimir,

it would be useful if you include a code sample illustrating the problem.
Thanks.


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

OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
VS 2005 version 8.0.50727.51
ReSharper build 251



0
Avatar
Permanently deleted user

// I attached screenshots with error highlights and full code that caused the problem to my first message.

0
Avatar
Permanently deleted user

Hmmm... It seems there is a small bug in the forum engine.
I copy-pasted code here but now I see extra closing angle bracket after KeyValuePair in my previous message. It shouldn't be there. You can see right code in the attachments.

0
Avatar
Permanently deleted user

/

  • I attached screenshots with error highlights and full code that caused the problem to my first message. */


using System;
using System.Collections;
using System.Collections.Generic;

public class Map : IEnumerable> /* bug in the forum engine - wrong extra closing angle bracket after 'KeyValuePair' is shown; see attachments for the right code */ { public static Map Compose( Map lhs, Map rhs) { Map map = new Map(); foreach (KeyValuePair pair in rhs) { TValue value = pair.Value; // lhs is Map, so lhs[value] is TSecond TSecond leftValue = lhs[value]; // Argument type 'TValue' is not assignable to parameter type 'TSecond' map.Add(pair.Key, leftValue); } return map; } void Add(TKey key, TValue value) { throw new NotImplementedException(); } public TValue this[TKey key] { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } } public IEnumerator>]]> GetEnumerator() /* bug in the forum engine - wrong extra closing angle bracket after 'KeyValuePair' is shown; see attachments for the right code */
{
throw new NotImplementedException();
}

IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}

Message was edited by:
Vladimir Reshetnikov

0
Avatar
Permanently deleted user

Thank you for the report'
The problem reproduced, will be fixed shortly

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Vladimir Reshetnikov" <no_reply@jetbrains.com> wrote in message
news:26938205.1150718354771.JavaMail.itn@is.intellij.net...

// I attached screenshots with error highlights and full code that caused
the problem to my first message.
using System;
using System.Collections;
using System.Collections.Generic;

>

public class Map<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
{
public static Map<TKey, TSecond> Compose<TSecond>(
Map<TValue, TSecond> lhs,
Map<TKey, TValue> rhs)
{
Map<TKey, TSecond> map = new Map<TKey, TSecond>();
foreach (KeyValuePair<TKey, TValue> pair in rhs)
{
map.Add(pair.Key, lhs[pair.Value]); // Argument type 'TValue' is not
assignable to parameter type 'TSecond'
}
return map;
}

>

void Add(TKey key, TValue value)
{
throw new NotImplementedException();
}

>

public TValue this[TKey key]
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}

>

public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
throw new NotImplementedException();
}

>

IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}



0
Avatar
Permanently deleted user

I've checked.
The problem is that type parameter name of method clashes with type
parameter name of the class.
Currently, ReSharper has problems in detecting such cases

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Vladimir Reshetnikov" <no_reply@jetbrains.com> wrote in message
news:26938205.1150718354771.JavaMail.itn@is.intellij.net...

// I attached screenshots with error highlights and full code that caused
the problem to my first message.
using System;
using System.Collections;
using System.Collections.Generic;

>

public class Map<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
{
public static Map<TKey, TSecond> Compose<TSecond>(
Map<TValue, TSecond> lhs,
Map<TKey, TValue> rhs)
{
Map<TKey, TSecond> map = new Map<TKey, TSecond>();
foreach (KeyValuePair<TKey, TValue> pair in rhs)
{
map.Add(pair.Key, lhs[pair.Value]); // Argument type 'TValue' is not
assignable to parameter type 'TSecond'
}
return map;
}

>

void Add(TKey key, TValue value)
{
throw new NotImplementedException();
}

>

public TValue this[TKey key]
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}

>

public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
throw new NotImplementedException();
}

>

IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}



0
Avatar
Permanently deleted user

will be fixed shortly

Eugene, it's great!
Thanks a lot.

0

Please sign in to leave a comment.