GNOME Bugzilla – Bug 607110
Class constructor doesn't allow requires.
Last modified: 2010-01-20 08:51:39 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. :)
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.
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.