From 63b2d4be9935ee48b342b7fe27f3f33bb9b7c6b3 Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 2 Jun 2020 16:40:24 +0800 Subject: [PATCH] cgen: make >8 indent levels work --- vlib/v/gen/cgen.v | 17 ++++++++++++++--- vlib/v/tests/if_expression_test.v | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 0aafe8efa9..b83714874d 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -517,8 +517,13 @@ pub fn (g Gen) save() { pub fn (mut g Gen) write(s string) { if g.indent > 0 && g.empty_line { - g.out.write(tabs[g.indent]) - // g.line_len += g.indent * 4 + if g.indent < tabs.len { + g.out.write(tabs[g.indent]) + } else { + for _ in 0 .. g.indent { + g.out.write('\t') + } + } } g.out.write(s) g.empty_line = false @@ -526,7 +531,13 @@ pub fn (mut g Gen) write(s string) { pub fn (mut g Gen) writeln(s string) { if g.indent > 0 && g.empty_line { - g.out.write(tabs[g.indent]) + if g.indent < tabs.len { + g.out.write(tabs[g.indent]) + } else { + for _ in 0 .. g.indent { + g.out.write('\t') + } + } } g.out.writeln(s) g.empty_line = true diff --git a/vlib/v/tests/if_expression_test.v b/vlib/v/tests/if_expression_test.v index 3bd8b0062b..96c8ca611d 100644 --- a/vlib/v/tests/if_expression_test.v +++ b/vlib/v/tests/if_expression_test.v @@ -128,3 +128,31 @@ fn test_complex_nested_if_expressions() { } assert a == false } + +fn test_lots_of_if_expressions() { + mut a := 0 + if true { + if true { + if true { + if true { + if true { + if true { + if true { + if true { + if true { + if true { + if true { + a = 1 + } + } + } + } + } + } + } + } + } + } + } + assert a == 1 +}