I see no other explanation when looking at such code:
public interface IParam
{
}
public class Param : IParam
{
}
public interface ITest<out T> where T : IParam
{
}
public class Test : ITest<Param>
{
}
public class Tester
{
public void Run<O>(ITest<O> a)
where O : IParam
{
Get(a); // ERROR
ITest<Param> b = new Test();
Get(b); // OK
}
public void Get(ITest<IParam> input)
{
}
}
Despite both types a
in b
are declared effectively with type parameter derived from IParam
only the second passes compilation.
Yet so far I didn't find a notice saying constraints are ignored when dealing with covariance/contravariance. Am I missing something or indeed it is the case (constraints are ignored)?