Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with recursive generic type in c#

I've got some C# code that compiles fine under both mono and the Microsoft's .net compilers, but only runs on mono. The error message is (newlines added by me)

Unhandled Exception: System.TypeLoadException:
Could not load type 'Hasse.Groups.Heavy.Product.PowerGroup`1'
from assembly 'Hasse, Version=1.0.x.y, Culture=neutral, PublicKeyToken=null'
because it has recursive generic definition.

The type actually has a recursive generic definition, so my question is: why does it work with mono? [The code runs and produces the expected result]

Full source code is here: https://github.com/miniBill/Hasse

Reduced code which still crashes is here:

public class Group<T> : IWrappableGroup<WrapperGroup<T>> {}

public class WrapperElement<T> {}

public interface IWrappableGroup<U> {}

public class WrapperGroup<T> : Group<WrapperElement<T>> {}

class MainClass {
    public static void Main(string[] args){
        var ng = new Group<object>();
    }
}

Here is proof that it works on mono: http://ideone.com/ZvA3I

like image 336
miniBill Avatar asked Jul 02 '12 14:07

miniBill


1 Answers

This is a known issue. It could be reported as a compiler error.

http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-335.pdf (page 129)

As for working in Mono, there are several places where Mono working is "broken" as far as the specs is concerned.

(Recursive lambdas are another exmaple of something that works in Mono that shouldn't)

like image 172
Matthew Whited Avatar answered Nov 02 '22 16:11

Matthew Whited