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 607110 - Class constructor doesn't allow requires.
Class constructor doesn't allow requires.
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Objects
0.7.x
Other Linux
: Normal minor
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2010-01-15 22:51 UTC by act1v8
Modified: 2010-01-20 08:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
The source code that generated the error. (124 bytes, text/plain)
2010-01-15 22:51 UTC, act1v8
  Details
Bug 607110 - Class constructor doesn't allow requires. (2.09 KB, patch)
2010-01-17 15:36 UTC, Marc-Andre Lureau
none Details | Review

Description act1v8 2010-01-15 22:51:08 UTC
Created attachment 151505 [details]
The source code that generated the error.

The constructor of a class doesn't allow using contract programming, i.e. the requires keyword. The compiler gives a compile-time error that looks like: test.vala:5.5-5.12: error: syntax error, expected `{'
    requires (test_value > 1)
    ^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)

The source code that created the error above is attached. (And yes, I know it doesn't have the main method, that is unimportant for this test case.)

Why would one want to use contract programming on a constructor? Because one would want to make sure that the parameters/arguments are what they are supposed to be. Of course, the simple requires (...) on a constructor isn't much more than a simple assert(...) at the beginning of the constructor, but if Vala is "advertised" to have this capability, it should. :)
Comment 1 Marc-Andre Lureau 2010-01-17 15:36:22 UTC
Created attachment 151605 [details] [review]
Bug 607110 - Class constructor doesn't allow requires.

Straight-forward fix, although it might be intentional it was left out.
Comment 2 Jürg Billeter 2010-01-20 08:51:39 UTC
commit ef7bf64f7544384dbe6dd375609f9413bb2c7e84
Author: Marc-André Lureau <marcandre.lureau@gmail.com>
Date:   Sun Jan 17 16:35:46 2010 +0100

    Accept pre- and postconditions for constructors
    
    Fixes bug 607110.