• entries
359
237
• views
189179

# Tangent: Generic Method Bodies, Part 1

223 views

Had some time yesterday, and more importantly some motivation. So continuing along towards reusable user-defined properties, I set into making generic methods work. The type inference had been done for a while (so I thought!) so this work mostly involved doing proper name resolution, and providing a runtime mechanism to retrieve what the generic was set to.

Alas, type inference was not quite done. The compiler did type inference properly, but the runtime didn't actually bind the runtime type to the generic type variable. So the compiler essentially guaranteed that it would run, but I ran into trouble once I tried to see what T really was.

So that fix was a bit awkward and annoying. The other mild problem was how the variable lookup was done. There is two parts to it really. The first is finding the generic itself so that the type-checker can reason about what it could possibly be. The second is actually looking up what runtime type it has so that it can be instantiated or otherwise worked with. Those are unfortunately a little awkward to do together. The end result was a little hackery to deal with inferred type parameters which were the main sticking point.

The test code of the day:

public class foo{	public abstract ToString()=>string;}public static print2( arg)=>void{        //local T tmp = arg;         // 55 - make sure that assignment/type checking works.	//local T tmp;               // 00 - make sure that the default initializer is smart about identifying the type.        local T tmp = new T;         // 00 - make sure that new T can be identified and dealt with	print tmp tmp;}public static main()=>void{	local foo aFoo = 5;	print2 aFoo;}

There are no comments to display.

## Create an account

Register a new account