Skip to content

Commit 63e87c1

Browse files
committed
typestate_check can now handle expr_block, expr_if, and expr_binary
(caveat for the latter: it assumes that binary operations are strict; a TODO is to detect or and and and correctly reflect that they're lazy in the second argument). I had to add an ann field to ast.block, resulting in the usual boilerplate changes. Test cases that currently work (if you uncomment the typestate pass in the driver) (all these are under test/compile-fail): fru-typestate ret-uninit use-uninit use-uninit-2 use-uninit-3
1 parent d3409f6 commit 63e87c1

File tree

6 files changed

+358
-161
lines changed

6 files changed

+358
-161
lines changed

src/comp/front/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ tag block_index_entry {
100100
}
101101
type block_ = rec(vec[@stmt] stmts,
102102
option.t[@expr] expr,
103-
hashmap[ident,block_index_entry] index);
103+
hashmap[ident,block_index_entry] index,
104+
ann a); /* ann is only meaningful for the ts_ann field */
104105

105106
type variant_def = tup(def_id /* tag */, def_id /* variant */);
106107

src/comp/front/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ fn index_block(vec[@ast.stmt] stmts, option.t[@ast.expr] expr) -> ast.block_ {
15981598
for (@ast.stmt s in stmts) {
15991599
ast.index_stmt(index, s);
16001600
}
1601-
ret rec(stmts=stmts, expr=expr, index=index);
1601+
ret rec(stmts=stmts, expr=expr, index=index, a=ast.ann_none);
16021602
}
16031603

16041604
fn index_arm(@ast.pat pat) -> hashmap[ast.ident,ast.def_id] {

src/comp/middle/fold.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,8 @@ fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block {
871871
}
872872
}
873873

874-
ret respan(blk.span, rec(stmts=stmts, expr=expr, index=index));
874+
auto aa = fld.fold_ann(env, blk.node.a);
875+
ret respan(blk.span, rec(stmts=stmts, expr=expr, index=index, a=aa));
875876
}
876877

877878
fn fold_arm[ENV](&ENV env, ast_fold[ENV] fld, &arm a) -> arm {

src/comp/middle/typeck.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,8 @@ mod Pushdown {
13991399
auto e_1 = pushdown_expr(fcx, expected, e_0);
14001400
auto block_ = rec(stmts=bloc.node.stmts,
14011401
expr=some[@ast.expr](e_1),
1402-
index=bloc.node.index);
1402+
index=bloc.node.index,
1403+
a=boring_ann());
14031404
ret fold.respan[ast.block_](bloc.span, block_);
14041405
}
14051406
case (none[@ast.expr]) {
@@ -2569,7 +2570,8 @@ fn check_block(&@fn_ctxt fcx, &ast.block block) -> ast.block {
25692570

25702571
ret fold.respan[ast.block_](block.span,
25712572
rec(stmts=stmts, expr=expr,
2572-
index=block.node.index));
2573+
index=block.node.index,
2574+
a=boring_ann()));
25732575
}
25742576

25752577
fn check_const(&@crate_ctxt ccx, &span sp, ast.ident ident, @ast.ty t,

0 commit comments

Comments
 (0)