• entries
    359
  • comments
    237
  • views
    188615

Tangent: Generic Method Bodies, Part 1

Sign in to follow this  

189 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;
}



Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now