[Mono-dev] Generic Variance Bug

Stefan Noack noackstefan at googlemail.com
Fri Sep 10 04:51:46 EDT 2010


Hi,

using mono from trunk, the following code compiles fine:

==> buggy.cs <==
namespace Buggy
{
    public interface ITest
    {
    }

    public interface ITestSpecialized : ITest
    {
    }

    public interface IGeneric<out TTest> where TTest : ITest
    {
        TTest Function();
    }

    public interface IDerived : IGeneric<ITest>
    {
    }

    public abstract class Implementation<TTest> : IGeneric<TTest>
where TTest : ITest
    {
        public TTest Function()
        {
            throw new System.NotImplementedException();
        }
    }

    public class MyClass : Implementation<ITestSpecialized>, IDerived
    {
    }
}

when i compile it

gmcs -t:library buggy.cs

no warning or error is issued and buggy.dll is successfully generated.

However, when i now want to use the created library:

==> buggy2.cs <==
namespace Buggy2
{
    public class Program
    {
        public static void Main()
        {
            Buggy.MyClass instance = new Buggy.MyClass();
        }
    }
}

compiling that code using

gmcs -r:buggy.dll buggy2.cs

produces the following output:

buggy2.cs(7,38): error CS0584: Internal compiler error: Could not
import type `Buggy.MyClass' from `/home/noah/prog/monobug/buggy.dll'
buggy2.cs(7,27): error CS0584: Internal compiler error: Could not
import type `Buggy.MyClass' from `/home/noah/prog/monobug/buggy.dll'
buggy2.cs(7,27): error CS0201: Only assignment, call, increment,
decrement, and new object expressions can be used as a statement
Compilation failed: 3 error(s), 0 warnings

Any ideas?

Best regards,
Stefan


More information about the Mono-devel-list mailing list