File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed
Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -124,8 +124,30 @@ fn check_expr(expr: &QccCell<Expr>) -> Result<Type> {
124124 check_expr ( expr) ;
125125 }
126126
127- // TODO:
128- Ok ( Type :: Bottom )
127+ let last_truth = truth_block. last ( ) ;
128+ let last_false = false_block. last ( ) ;
129+
130+ if last_false. is_none ( ) && last_truth. is_none ( ) {
131+ return Ok ( Type :: Bottom ) ;
132+ } else if last_false. is_none ( ) ^ last_truth. is_none ( ) {
133+ let last_expr;
134+ if last_false. is_none ( ) {
135+ last_expr = last_truth;
136+ } else {
137+ last_expr = last_false;
138+ }
139+
140+ return Ok ( last_expr. unwrap ( ) . as_ref ( ) . borrow ( ) . get_type ( ) ) ;
141+ } else {
142+ let truth_block_type = last_truth. unwrap ( ) . as_ref ( ) . borrow ( ) . get_type ( ) ;
143+ let false_block_type = last_false. unwrap ( ) . as_ref ( ) . borrow ( ) . get_type ( ) ;
144+
145+ if truth_block_type != false_block_type {
146+ return Err ( QccErrorKind :: TypeMismatch ) ?;
147+ }
148+
149+ return Ok ( truth_block_type) ;
150+ }
129151 }
130152 Expr :: Literal ( ref lit) => match * lit. as_ref ( ) . borrow ( ) {
131153 LiteralAST :: Lit_Digit ( ref digit) => Ok ( Type :: F64 ) ,
@@ -631,7 +653,7 @@ fn infer_from_table(
631653 return info;
632654 }
633655 }
634- // TODO: How to infer type for entire if block?
656+
635657 None
636658 }
637659 Expr :: Literal ( ref mut l) => {
You can’t perform that action at this time.
0 commit comments