From d359a7aefb4ad8c019232f33af568b0b6c9e2a63 Mon Sep 17 00:00:00 2001 From: Kris Cherven <50562493+krischerven@users.noreply.github.com> Date: Mon, 11 May 2020 17:49:08 -0400 Subject: [PATCH] cgen: fix a goto error --- vlib/v/gen/cgen.v | 2 +- vlib/v/tests/goto_test.v | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/goto_test.v diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index a21e1c2300..12e9068c5a 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -626,7 +626,7 @@ fn (mut g Gen) stmt(node ast.Stmt) { g.go_stmt(it) } ast.GotoLabel { - g.writeln('$it.name:') + g.writeln('$it.name: {}') } ast.GotoStmt { g.writeln('goto $it.name;') diff --git a/vlib/v/tests/goto_test.v b/vlib/v/tests/goto_test.v new file mode 100644 index 0000000000..f065893953 --- /dev/null +++ b/vlib/v/tests/goto_test.v @@ -0,0 +1,10 @@ +fn test_goto() { + mut i := 0 + a: b := 1 + _ = b + i++ + if i < 3 { + goto a + } + assert i == 3 +}