cgen: make >8 indent levels work

pull/5167/head
yuyi 2020-06-02 16:40:24 +08:00 committed by GitHub
parent ad8ed851d0
commit 63b2d4be99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 3 deletions

View File

@ -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

View File

@ -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
}