GNOME Bugzilla – Bug 530698
Cannot have local variables called error or self
Last modified: 2008-05-10 19:25:49 UTC
E.g the the code below code is accepted by the vala compiler but the C compiler complains because error and self are defined twice. Probably best to solve this by prefixing "hidden" variables with two underscores. One underscore is sometimes used by people for fields using GLib; public class Sample : GLib.Object{ public void foo () throws MyError { int error = 0; int self = 5; throw new MyError.FAILED ("Hello"); } static int main (string[] args) { return 0; } } public errordomain MyError { FAILED, SYNTAX }
Created attachment 110391 [details] [review] naive find & replace patch Done by find & replace. I didn't manually check that every single change is correct, but it all seems to work.
Thanks for the patch, however, I see two issues with the proposed patch. For one, there are more variables that can conflict, e.g. temporary variables and array length variables, and we should probably fix this together in a more general way. The other issue is that I only want to change the generated variable name where necessary instead of always using harder to read variable names everywhere, especially for parameter names like `self' that might be visible in public header files. It might even make sense to rename the local `self' variables instead of the generated `self' parameter.
Thanks for the bug report. This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find. *** This bug has been marked as a duplicate of 469335 ***