MCPcopy Create free account
hub / github.com/Schwenger/RustTyC / main

Function main

examples/parametrized_function.rs:180–197  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

178}
179
180fn 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
199fn build_complex_expression_type_checks() -> Expression {
200 use Expression::*;

Callers

nothing calls this directly

Calls 3

type_checkMethod · 0.80
tc_exprFunction · 0.70

Tested by

no test coverage detected