Yoric/Marv-the-Tinker — Issue #6: Implement preconditions/postconditions
Author: Yoric
Created: 2012-03-09 19:59:10+00:00
State: open

I would like to add pre/post conditions:

/**
* @pre {foo.value > 0} foo.value must be strictly positive.
* @post {foo.value >= 0} foo.value can be positive or 0.
*/
function decrement(foo) {
foo.value --;
}

This can be compiled to:

function decrement(foo) {
if (!(foo.value > 0)) {
throw new Error("Precondition failed (foo.value > ))");
}
foo.value --;
if (!(foo.value >= 0)) {
throw new Error("Postcondition failed (foo.value > ))");
}
}