From cf3dccca2cbcb57bef77b541cb1bae4f4d057d3f Mon Sep 17 00:00:00 2001 From: Natapat Samutpong Date: Sun, 20 Mar 2022 05:53:43 +0700 Subject: [PATCH] do blocks generate scope --- crates/codegen/src/ts.rs | 5 +++-- example/err/do_end_scope.hz | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 example/err/do_end_scope.hz diff --git a/crates/codegen/src/ts.rs b/crates/codegen/src/ts.rs index 8acba21..756f4dd 100644 --- a/crates/codegen/src/ts.rs +++ b/crates/codegen/src/ts.rs @@ -74,7 +74,7 @@ impl Codegen { .collect::>(). join(", "); format!( - "const f_{} = ({}): {} => {{\n{}\n}};\n", + "const f_{} = ({}): {} => {};\n", name, args, return_type_hint, @@ -90,10 +90,11 @@ impl Codegen { }, IRKind::Do { body } => { - let mut out = String::new(); + let mut out = "{\n".to_string(); for expr in body { out.push_str(&self.gen_ir(&expr, true)); } + out.push_str("}\n"); out }, diff --git a/example/err/do_end_scope.hz b/example/err/do_end_scope.hz new file mode 100644 index 0000000..eb68631 --- /dev/null +++ b/example/err/do_end_scope.hz @@ -0,0 +1,7 @@ +fun main: void = do + do + let foo: string = "Hello"; + @write(foo); + end; + @write(foo); -- TODO: This is a runtime error +end; \ No newline at end of file