@@ -1027,28 +1027,45 @@ mod writeback {
1027
1027
export resolve_type_vars_in_block;
1028
1028
1029
1029
fn resolve_type_vars_in_type( & @fn_ctxt fcx, & span sp, ty:: t typ) ->
1030
- ty:: t {
1031
- if ( !ty:: type_contains_vars( fcx. ccx. tcx, typ) ) { ret typ; }
1030
+ option :: t [ ty:: t] {
1031
+ if ( !ty:: type_contains_vars( fcx. ccx. tcx, typ) ) { ret some ( typ) ; }
1032
1032
alt ( ty:: unify:: fixup_vars( fcx. ccx. tcx, fcx. var_bindings, typ) ) {
1033
- case ( fix_ok( ?new_type) ) { ret new_type; }
1033
+ case ( fix_ok( ?new_type) ) { ret some ( new_type) ; }
1034
1034
case ( fix_err( ?vid) ) {
1035
- fcx. ccx. tcx. sess. span_fatal ( sp,
1035
+ fcx. ccx. tcx. sess. span_err ( sp,
1036
1036
"cannot determine a type \
1037
1037
for this expression") ;
1038
+ ret none;
1038
1039
}
1039
1040
}
1040
1041
}
1041
- fn resolve_type_vars_for_node( & @fn_ctxt fcx, & span sp, ast:: node_id id) {
1042
+ fn resolve_type_vars_for_node( & @wb_ctxt wbcx,
1043
+ & span sp, ast:: node_id id) {
1044
+ auto fcx = wbcx. fcx;
1042
1045
auto tpot = ty:: node_id_to_ty_param_substs_opt_and_ty
1043
1046
( fcx. ccx. tcx, id) ;
1044
- auto new_ty = resolve_type_vars_in_type( fcx, sp, tpot. _1) ;
1047
+ auto new_ty = alt ( resolve_type_vars_in_type( fcx, sp, tpot. _1) ) {
1048
+ case ( some( ?t) ) { t }
1049
+ case ( none) {
1050
+ wbcx. success = false;
1051
+ ret
1052
+ }
1053
+ } ;
1045
1054
auto new_substs_opt;
1046
1055
alt ( tpot. _0) {
1047
1056
case ( none[ vec[ ty:: t] ] ) { new_substs_opt = none[ vec[ ty:: t] ] ; }
1048
1057
case ( some[ vec[ ty:: t] ] ( ?substs) ) {
1049
1058
let vec[ ty:: t] new_substs = [ ] ;
1050
1059
for ( ty:: t subst in substs) {
1051
- new_substs += [ resolve_type_vars_in_type( fcx, sp, subst) ] ;
1060
+ alt ( resolve_type_vars_in_type( fcx, sp, subst) ) {
1061
+ case ( some( ?t) ) {
1062
+ new_substs += [ t] ;
1063
+ }
1064
+ case ( none) {
1065
+ wbcx. success = false;
1066
+ ret;
1067
+ }
1068
+ }
1052
1069
}
1053
1070
new_substs_opt = some[ vec[ ty:: t] ] ( new_substs) ;
1054
1071
}
@@ -1058,19 +1075,20 @@ mod writeback {
1058
1075
1059
1076
type wb_ctxt = rec( @fn_ctxt fcx,
1060
1077
// A flag to ignore contained items and lambdas
1061
- mutable bool ignore) ;
1078
+ mutable bool ignore,
1079
+ mutable bool success) ;
1062
1080
1063
1081
fn visit_stmt_pre( @wb_ctxt wbcx, & @ast:: stmt s) {
1064
- resolve_type_vars_for_node( wbcx. fcx , s. span, ty:: stmt_node_id( s) ) ;
1082
+ resolve_type_vars_for_node( wbcx, s. span, ty:: stmt_node_id( s) ) ;
1065
1083
}
1066
1084
fn visit_expr_pre( @wb_ctxt wbcx, & @ast:: expr e) {
1067
- resolve_type_vars_for_node( wbcx. fcx , e. span, e. id) ;
1085
+ resolve_type_vars_for_node( wbcx, e. span, e. id) ;
1068
1086
}
1069
1087
fn visit_block_pre( @wb_ctxt wbcx, & ast:: block b) {
1070
- resolve_type_vars_for_node( wbcx. fcx , b. span, b. node. id) ;
1088
+ resolve_type_vars_for_node( wbcx, b. span, b. node. id) ;
1071
1089
}
1072
1090
fn visit_pat_pre( @wb_ctxt wbcx, & @ast:: pat p) {
1073
- resolve_type_vars_for_node( wbcx. fcx , p. span, p. id) ;
1091
+ resolve_type_vars_for_node( wbcx, p. span, p. id) ;
1074
1092
}
1075
1093
fn visit_local_pre( @wb_ctxt wbcx, & @ast:: local l) {
1076
1094
auto var_id = lookup_local( wbcx. fcx, l. span, l. node. id) ;
@@ -1105,11 +1123,12 @@ mod writeback {
1105
1123
& ast:: fn_ident i, ast:: node_id d) {
1106
1124
wbcx. ignore = false;
1107
1125
}
1108
- fn keep_going( @wb_ctxt wbcx) -> bool { ret !wbcx. ignore; }
1126
+ fn keep_going( @wb_ctxt wbcx) -> bool { !wbcx. ignore && wbcx . success }
1109
1127
1110
- fn resolve_type_vars_in_block( & @fn_ctxt fcx, & ast:: block block) {
1128
+ fn resolve_type_vars_in_block( & @fn_ctxt fcx, & ast:: block block) -> bool {
1111
1129
auto wbcx = @rec( fcx = fcx,
1112
- mutable ignore = false) ;
1130
+ mutable ignore = false,
1131
+ mutable success = true) ;
1113
1132
auto visit =
1114
1133
rec( keep_going=bind keep_going( wbcx) ,
1115
1134
visit_item_pre=bind visit_item_pre( wbcx, _) ,
@@ -1123,6 +1142,7 @@ mod writeback {
1123
1142
visit_local_pre=bind visit_local_pre( wbcx, _)
1124
1143
with walk:: default_visitor( ) ) ;
1125
1144
walk:: walk_block( visit, block) ;
1145
+ ret wbcx. success;
1126
1146
}
1127
1147
}
1128
1148
@@ -2482,9 +2502,9 @@ fn check_fn(&@crate_ctxt ccx, &ast::fn_decl decl, ast::proto proto,
2482
2502
case ( _) { }
2483
2503
}
2484
2504
2485
- writeback:: resolve_type_vars_in_block( fcx, body) ;
2505
+ auto success = writeback:: resolve_type_vars_in_block( fcx, body) ;
2486
2506
2487
- if ( option:: is_some( body. node. expr) ) {
2507
+ if ( success && option:: is_some( body. node. expr) ) {
2488
2508
auto tail_expr = option:: get( body. node. expr) ;
2489
2509
auto tail_expr_ty = expr_ty( ccx. tcx, tail_expr) ;
2490
2510
// Have to exclude ty_nil to allow functions to end in
0 commit comments