Spent some more time on generic constraints. Some things are a bit surprising at first sight and so my first attempt to implement this was wrong:
This example is ok and allowed - you may pass hello to that function since the constraints match. However, the following is not allowed:
The constraints just say that Y must derive from X - but this function still takes a Hello<Y> argument. You cannot interpret the constraints in a way that any generic instance Hello<T> is allowed, if just T derives from Y.
Spent most of the day working on generic methods in interfaces and their constraints. If you have a generic method in an interface and you explicitly implement this interface method, you may not specify any constraints on that implementation - they're automatically inherited from the declaration in the interface:
The same applies when overriding an abstract or virtual method.
However, if you implement the interface method implicitly, you must repeat the constraints - and they may not conflict with the ones from the declaration in the interface:
Today, I tracked a really bad boy down which caused very weird failures of gmcs compiled assemblies on the MS runtime. So, while looking at the following example, I made some interesting obervations:
.class interface private abstract auto ansi 'IFoo`1'<T>
and
.class private auto ansi beforefieldinit 'Foo`1'<T>
extends [mscorlib]System.Object
implements class 'IFoo`1'<!T>
.method private hidebysig newslot virtual final instance void 'IFoo<T>.Test'<u>(!T t, !!U u) cil managed
Note that this does not include the generic arity like in the class name.
.override method instance void class 'IFoo`1'<!T>::Test<[1]>(!0,!!U)
Last week, Peter Sestoft and Niels Jørgen Kokholm released C5, a comprehensive library of generic collection classes for C# 2.0.
This is really good news for me, since it gives me plenty of test cases for GMCS - it can't compile C5 yet, but I'm really confident that I can fix the bugs really soon. This'll bring us one step further on the way to a stable, high-quality compiler for C# generics.
I imported a copy of this library into CVS (mcs/class/Mono.C5), but it isn't included in the build yet.
So this is finally it, the very last picture of my old car:
Now it's finally time to say goodbye ....
This is it, the sad and final end of my old car.
Just took a very last picture of it and removed the license plates. Now it's time to say goodbye and look forward to getting a new car ....