After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 611490 - Calling instance methods in ctors should be disallowed
Calling instance methods in ctors should be disallowed
Status: RESOLVED DUPLICATE of bug 567269
Product: vala
Classification: Core
Component: Parser
0.7.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2010-03-01 15:36 UTC by Cyrille Chépélov
Modified: 2010-03-22 21:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
this will crash on class Derived3Bad, if built with --enabled-checking, (3.29 KB, text/x-vala)
2010-03-01 15:36 UTC, Cyrille Chépélov
Details

Description Cyrille Chépélov 2010-03-01 15:36:46 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
Comment 1 Jürg Billeter 2010-03-22 21:09:59 UTC
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 ***