From 6f4833f84dd3ec17311b5e6ca9f5c1ad94ff7564 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Fri, 29 Mar 2024 11:31:47 +0100 Subject: Improve the error messages --- compiler/PrePasses.ml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'compiler/PrePasses.ml') diff --git a/compiler/PrePasses.ml b/compiler/PrePasses.ml index 42857a88..8c346a8c 100644 --- a/compiler/PrePasses.ml +++ b/compiler/PrePasses.ml @@ -214,14 +214,17 @@ let remove_loop_breaks (crate : crate) (f : fun_decl) : fun_decl = object inherit [_] map_statement as super - method! visit_Loop entered_loop loop = - cassert (not entered_loop) st.meta - "Nested loops are not supported yet"; - super#visit_Loop true loop - - method! visit_Break _ i = - cassert (i = 0) st.meta "Breaks to outer loops are not supported yet"; - nst.content + method! visit_statement entered_loop st = + match st.content with + | Loop loop -> + cassert (not entered_loop) st.meta + "Nested loops are not supported yet"; + { st with content = super#visit_Loop true loop } + | Break i -> + cassert (i = 0) st.meta + "Breaks to outer loops are not supported yet"; + { st with content = nst.content } + | _ -> super#visit_statement entered_loop st end in obj#visit_statement false st -- cgit v1.2.3