GNOME Bugzilla – Bug 611490
Calling instance methods in ctors should be disallowed
Last modified: 2010-03-22 21:09:59 UTC
Created attachment 154953 [details] this will crash on class Derived3Bad, if built with --enabled-checking, in C#, the following is illegal: class Derived: Root { private /* NOT STATIC */ int GetMul() { return Whatever; } public Derived(int foo): base(foo * GetMul() ) // Illegal in C# { _applied_mul = GetMul(); // this is legal } readonly int _applied_mul; } in Vala, this is accepted: class Derived { private /* NOT STATIC */ int get_mul() { return 42; // notice: not actually touching any instance resources } public Derived(int foo) { base(foo * get_mul()); } but will cause a segfault *if* the code is build with --enable-checking (it'll go ahead on regular code, to the extent get_mul() is not touching "this") It seems to me that calling instance methods in a ctor (or clone ctor) should be illegal as long as the actual "self" object hasn't been _construct()'ed. Tested on Vala 0.7.10 on a Debian squeeze/sid amd64 box. The attached test case will crash on Derived3Bad if compiled with --enable-checking (on the emitted g_assert(self != null)) or on Derived4Worse if compiled without (because of an actual early use of "self"). In both cases, my opinion is that the code should be illegal or at the very least warn against shooting into one's foot. Thanks in advance. issue on Vala encountered during http://mail.gnome.org/archives/rygel-list/2010-March/msg00000.html
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 bug 567269 ***