Standard Library · meta
class Contract
One contract clause of a method or class, as a rule sees it: a pre, a post or an invariant.
since 0.1.0-alpha.1linuxwindowswasm
Overview
meta::Method.contracts lists a method's own clauses and meta::Class.invariants a class's own invariants, in written order; inherited clauses are not listed.
Examples
use io::console;
attribute Inspect { }
rule inspect {
match @Inspect(i) on class C
inject `Array<string> clauses() => [ $for s in C.methods.where((m) => m.contracts.length() > 0).map((m) =>
m.name + ": " + m.contracts.map((c) => c.kind + "(" + c.text + ")").joinToString(" ")) : $s ];` at member of C
}
@Inspect
class Account {
int balance = 0;
void deposit(int cents) pre(cents > 0) { balance = balance + cents; }
int read() => balance;
}
console.writeln(Account().clauses().joinToString("; "));
deposit: pre(cents > 0)
Fields
isDebug
bool isDebugtrue for a clause written with @Debug.
kind
string kind"pre", "post" or "invariant".
result
string resultA post's result name (the r of post(r: ...)); "" when the clause names none.
text
string textThe predicate's source text, exactly as written between the parentheses (after a post's r:).