public Map<string,string> variable_name_map = new HashMap<string,string> (str_hash, str_equal);
public Map<string,int> closure_variable_count_map = new HashMap<string,int> (str_hash, str_equal);
public Map<LocalVariable,int> closure_variable_clash_map = new HashMap<LocalVariable,int> ();
+ public bool is_in_method_precondition;
public EmitContext (Symbol? symbol = null) {
current_symbol = symbol;
set { emit_context.current_inner_error_id = value; }
}
+ public bool is_in_method_precondition {
+ get { return emit_context.is_in_method_precondition; }
+ set { emit_context.is_in_method_precondition = value; }
+ }
+
public TypeSymbol? current_type_symbol {
get {
var sym = current_symbol;
} else {
string name = get_ccode_name (param);
- if (param.captured) {
+ if (param.captured && !is_in_method_precondition) {
// captured variables are stored on the heap
var block = param.parent_symbol as Block;
if (block == null) {
}
private void create_precondition_statement (Method m, DataType ret_type, Expression precondition) {
+ is_in_method_precondition = true;
+
var ccheck = new CCodeFunctionCall ();
precondition.emit (this);
ccode.add_expression (ccheck);
current_method_return = true;
+ is_in_method_precondition = false;
}
public override void visit_creation_method (CreationMethod m) {
methods/iterator.vala \
methods/parameter-ref-array-resize.vala \
methods/prepostconditions.vala \
+ methods/prepostconditions-captured.vala \
methods/postconditions.vala \
methods/same-name.vala \
methods/symbolresolution.vala \
--- /dev/null
+delegate void Func ();
+
+int bar (int i) requires (i == 23) ensures (i == 42) {
+ Func f = () => {
+ assert (i == 23);
+ i = 42;
+ };
+ f ();
+
+ return i;
+}
+
+void baz (int i) requires (i == 42) ensures (i == 23) {
+ Func f = () => {
+ assert (i == 42);
+ i = 23;
+ };
+ f ();
+}
+
+async int foo (int i) requires (i == 23) ensures (i == 42) {
+ Func f = () => {
+ assert (i == 23);
+ i = 42;
+ };
+ f ();
+
+ return i;
+}
+
+void main () {
+ assert (bar (23) == 42);
+ baz (42);
+ foo.begin (23);
+}