Error when setting default value of method parameter to 'this'
Submitted by bra..@..il.com
Link to original bug (#674644)
Description
Created attachment 212626 Code used in example
When you set the default value of a method's parameter to 'this', gcc is unable to compile the resulting C code. (This is done a lot when implementing recursive functions on structures, so I added this as a major bug.) Example: (code also attached)
$ cat test.vala
class Number : Object { public int val {get; set; default = 1;}
public int factorial(Number n = this) {
Number n_sub_1 = new Number();
n_sub_1.val = n.val - 1;
return (n.val == 1) ? 1 : n.val * factorial(n_sub_1);
}
}
class Main : Object { public static int main(string[] args) { Number num = new Number(); num.val = 5; stdout.printf("%d\n", num.factorial());
return 0;
}
}
$ valac-0.16 --version
Vala 0.16.0
$ cc --version
cc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1 Copyright (C) 2011 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ valac-0.16 test.vala
/home//Programming/Vala/test.vala.c: In function ‘main_main’: /home//Programming/Vala/test.vala.c:229:34: error: ‘self’ undeclared (first use in this function) /home/***/Programming/Vala/test.vala.c:229:34: note: each undeclared identifier is reported only once for each function it appears in error: cc exited with status 256 Compilation failed: 1 error(s), 0 warning(s)
Attachment 212626, "Code used in example":
test.vala