v2: fix for position and check
parent
042bce4b6c
commit
bc11419ff9
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue