checker: fix `L1: for{ for{} }` incorrectly setting c.loop_label to '' after the inner loop

pull/7270/head
Delyan Angelov 2020-12-11 13:11:17 +02:00
parent 90b5f6f4e0
commit df4ec89a03
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 6 additions and 3 deletions

View File

@ -2551,16 +2551,18 @@ fn (mut c Checker) stmt(node ast.Stmt) {
}
ast.ForCStmt {
c.in_for_count++
prev_loop_label := c.loop_label
c.stmt(node.init)
c.expr(node.cond)
c.stmt(node.inc)
c.check_loop_label(node.label, node.pos)
c.stmts(node.stmts)
c.loop_label = ''
c.loop_label = prev_loop_label
c.in_for_count--
}
ast.ForInStmt {
c.in_for_count++
prev_loop_label := c.loop_label
typ := c.expr(node.cond)
typ_idx := typ.idx()
if node.key_var.len > 0 && node.key_var != '_' {
@ -2613,11 +2615,12 @@ fn (mut c Checker) stmt(node ast.Stmt) {
}
c.check_loop_label(node.label, node.pos)
c.stmts(node.stmts)
c.loop_label = ''
c.loop_label = prev_loop_label
c.in_for_count--
}
ast.ForStmt {
c.in_for_count++
prev_loop_label := c.loop_label
c.expected_type = table.bool_type
typ := c.expr(node.cond)
if !node.is_inf && typ.idx() != table.bool_type_idx && !c.pref.translated {
@ -2627,7 +2630,7 @@ fn (mut c Checker) stmt(node ast.Stmt) {
// how does this work currenly?
c.check_loop_label(node.label, node.pos)
c.stmts(node.stmts)
c.loop_label = ''
c.loop_label = prev_loop_label
c.in_for_count--
}
ast.GlobalDecl {