🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Tangent: Buggery

Published August 25, 2008
Advertisement
Ran into an interesting bug over the weekend, and fixed today. The following code was in error:

public class foo{    public operator delegate int op(int x, int y);}public static void main(){    local foo x = new foo;    x.op = (int x, int y) => int{return(x+y);};    print 2 x.op 6;}


The error was Unknown identifier 'lhs'

Sure, no line numbers sucks, but there's no lhs identifier in here. In debug mode, I could find the source of the error and it resolved to my built-in minus operator (which takes lhs/rhs as parameters). It thought that its parameter names were x/y. So it kinda appears to be that the lambda is leaking somehow and overwriting the names. Or that their shared base class (BinaryOperator) was getting its names set and then propagating them improperly.

Turned out to be a little more simple than that. Parameter names are a little bit of a hack at this point. A method can have an extra member called ParameterNames which is a tuple of voids that have their member-names set accordingly. Thus the lambda would be:

Parameters: int "0"/int "1"ParameterNames: void "x"/void "y"


Ugly, and even I don't remember quite why it's setup like this. Anyways, the problem was caused by caching of the tuple results. If you ask for int,int you don't get a new type that is int tuple int you get the one and only type int tuple int. The member names though don't matter for tuple type equality. So when the lambda asked for void tuple void to set the parameter names, it got the one and only void tuple void (which minus was using for its parameter names) and overwrote the name values.

So now a check is done to prevent caching when one of the members in the tuple is void.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement