v2: fix for position and check

pull/3779/head
Alexander Medvednikov 2020-02-19 11:06:36 +01:00
parent 042bce4b6c
commit bc11419ff9
3 changed files with 15 additions and 13 deletions

View File

@ -338,9 +338,10 @@ pub:
pub struct ForStmt {
pub:
cond Expr
stmts []Stmt
pos token.Position
cond Expr
stmts []Stmt
pos token.Position
is_inf bool // `for {}`
}
pub struct ForInStmt {

View File

@ -273,7 +273,7 @@ fn (c mut Checker) stmt(node ast.Stmt) {
typ := c.expr(it.cond)
// typ_sym := c.table.get_type_symbol(typ)
// if typ_sym.kind != .bool {
if table.type_idx(typ) != table.bool_type_idx {
if !it.is_inf && table.type_idx(typ) != table.bool_type_idx {
c.error('non-bool used as for condition', it.pos)
}
for stmt in it.stmts {

View File

@ -91,7 +91,6 @@ pub fn parse_file(path string, table &table.Table) ast.File {
for p.tok.kind == .key_import {
imports << p.import_stmt()
}
// TODO: import only mode
for {
// res := s.scan()
@ -893,11 +892,13 @@ fn (p mut Parser) for_statement() ast.Stmt {
// defer { p.close_scope() }
// Infinite loop
if p.tok.kind == .lcbr {
pos := p.tok.position()
stmts := p.parse_block()
p.close_scope()
return ast.ForStmt{
stmts: stmts
pos: p.tok.position()
pos: pos
is_inf: true
}
}
else if p.tok.kind == .key_mut {