graydon/rust — Issue #1259: Typestate doesn't track initialization through closures
Author: jdm
Created: 2011-12-05 02:19:18+00:00
State: open
Labels: middle, typestate

```rust
fn foo(bl: block(int)) {
let val = 5;
bl(val);
}

fn main() {
let val;
foo({|new_val| val = new_val;});
log_err val;
}
```

yields this error:

```
/Users/jdm/src/closure.rs:8:8: 8:34 error: Unsatisfied precondition constraint (for example, init(val [/Users/jdm/src/closure.rs:7:8: 7:11])) for expression:
{|new_val| val = new_val; }
Precondition:
init(val [/Users/jdm/src/closure.rs:7:8: 7:11])
Prestate:
!init(val [/Users/jdm/src/closure.rs:7:8: 7:11]), !init(main [/Users/jdm/src/closure.rs:6:0: 10:0]), !init(main! [/Users/jdm/src/closure.rs:6:0: 10:0])
/Users/jdm/src/closure.rs:8 foo({|new_val| val = new_val;});
^~~~~~~~~~~~~~~~~~~~~~~~~~
rust: upcall fail 'explicit failure', ../src/comp/driver/session.rs:66
rust: domain main @0x10202c400 root task failed
```