October 24, 2003 05:34 am

Inheriting from a constructed type

While playing around with yesterday's example, I realized that there's another problem which needs to be solved first:

class Foo<T> { public void Hello () { } public void World (T t) { Hello (); } } class Bar : Foo<int> { public void Test () { Hello (); World (4); } }

The problem is that gmcs calls ConstructedType.ResolveAsTypeStep on Foo<int> before defining Foo's members. This makes the member lookup for Hello fail.

Finally got this working. This is very similar to MethodBuilders: at the time we create the MethodBuilder (this is done in TypeContainer.DefineType() we don't have its methods yet; they're created later in TypeContainer.DefineMembers().

We just need to do the same for generic types: at the time we instantiate the generic type, we don't have the methods yet, so we can't inflate them right away. Instead, we now create a special System.Reflection.MonoGenericInst instance which overrides Type.GetMethods and Type.GetConstructors and inflates everything the first time it is called.

Posted by martin at October 24, 2003 05:34 am.