diff --git a/src/ast/main.rs b/src/ast/main.rs index 4b310e9a9bd5fc27863f6fdec9b9e4c3d8fbcca2..825a7ff3e4a83504fcc4fdcebde9ba51fc0b3ec5 100644 --- a/src/ast/main.rs +++ b/src/ast/main.rs @@ -31,17 +31,18 @@ fn parse_num_or_id() { type Error = String; fn type_check(stmts: &Stmts) -> Result<(), Error> { - for i in stmts { - match i { - Stmt::Let(_, _) => { - println!("let"); - } - Stmt::If(_, _, __) => { - println!("if"); - } + let r: Result<(), Error> = stmts.iter().try_for_each(|i| match i { + Stmt::Let(_, _) => { + println!("let"); + Ok(()) } - } - Ok(()) + Stmt::If(_, _, __) => { + println!("if"); + Err("error in if".to_string())? + } + }); + println!("here we can do something before returning"); + r } #[test] @@ -49,6 +50,7 @@ fn test_stmts() { let stmts = vec![ Stmt::Let("a".to_string(), NumOrId::Num(1)), Stmt::Let("b".to_string(), NumOrId::Num(2)), + Stmt::If("b".to_string(), Stmts::new(), None), Stmt::Let("c".to_string(), NumOrId::Num(3)), ]; type_check(&stmts).unwrap();