()
| 178 | } |
| 179 | |
| 180 | fn main() { |
| 181 | // Build an expression to type-check. |
| 182 | let expr = build_complex_expression_type_checks(); |
| 183 | // Create an empty type checker. |
| 184 | let mut tc: VarlessTypeChecker<Variant> = TypeChecker::without_vars(); |
| 185 | // Type check the expression. |
| 186 | let res = tc_expr(&mut tc, &expr).and_then(|key| tc.type_check().map(|tt| (key, tt))); |
| 187 | match res { |
| 188 | Ok((key, tt)) => { |
| 189 | let res_type = tt[&key]; |
| 190 | // Expression `if true then 2.7^3 + 4.3 else 3` should yield type Fixed(3, 3) because the addition requires a |
| 191 | // Fixed(2,3) and a Fixed(3,3), which results in a Fixed(3, 3). |
| 192 | // Constructing an actual type yields Type::FixedPointI64F64. |
| 193 | assert_eq!(res_type, Type::FixedPointI64F64); |
| 194 | } |
| 195 | Err(_) => panic!("Unexpected type error!"), |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | fn build_complex_expression_type_checks() -> Expression { |
| 200 | use Expression::*; |
nothing calls this directly
no test coverage detected