Rare compiler/analysis bug

There seems to be a rare bug involving a non-generic type nested under a generic type, that is in another assembly.

I'm not sure I can get it to occur in an example.

The problem involves Rider/Resharper not substituting known type arguments for the type parameters, and complaining that the type parameter is not compatible with the type argument. It may also have to be in another assembly.

I have something like the following:

public class Outer<T> {
public class Inner {
}
}

public class Something {
Outer<int>.Inner GetInner() =>
new Outer<int>.Inner();
}

...

// somewhere else, in a different project
var s = new Something();
Outer<int>.Inner inner = s.GetInner(); // ERROR

// Cannot convert source type Outer<T>.Inner to target type Outer<int>.Inner

// if I use var, then the type is inferred as Outer<T>.Inner and I get
// conversion errors later if I try to use a member of type T,
// which should be type int instead

I can get around it using a hard cast:

var inner = (Outer<int>.Inner)(object)s.GetInner();

This is a Rider/Resharper specific bug. MSBuild will build the project fine despite these errors in the IDE.

0
1 comment
Hello,
thank you for contacting us.
Could you please install our latest EAP from here: https://www.jetbrains.com/resharper/nextversion/#section=windows and check how it works for you?
Thank you!
0

Please sign in to leave a comment.