improve `[Assert]` attribute
Currently the compiler does not seem to enforce any requirements on functions declared with [Assert]
. Here are some possible rules for such functions:
- they must return
void
- they must have their first argument be a
bool expr
- if the
expr
is false then the function must terminate the program
Example of `[Assert]` being allowed in any context
[Assert]
bool f () {
return true;
}
[Assert]
void x () {
}
void main () {
f ();
x ();
assert (true);
}
Leads to:
/home/pferro/assert.vala.c: In function ‘_vala_main’:
/home/pferro/assert.vala.c:41:29: error: macro "_vala_assert" requires 2 arguments, but only 1 given
41 | _vala_assert ("f ()");
| ^
/home/pferro/assert.vala.c:16: note: macro "_vala_assert" defined here
16 | #define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
|
/home/pferro/assert.vala.c:41:9: error: ‘_vala_assert’ undeclared (first use in this function)
41 | _vala_assert ("f ()");
| ^~~~~~~~~~~~
/home/pferro/assert.vala.c:41:9: note: each undeclared identifier is reported only once for each function it appears in
/home/pferro/assert.vala.c:42:29: error: macro "_vala_assert" requires 2 arguments, but only 1 given
42 | _vala_assert ("x ()");
| ^
/home/pferro/assert.vala.c:16: note: macro "_vala_assert" defined here
16 | #define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
|
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)
Edited by Princeton Ferro