v2: report ill defined consts by name/line, not only how many they are

pull/4210/head
Delyan Angelov 2020-04-02 22:31:36 +03:00
parent 5b6ec8996a
commit 07c53b1b70
4 changed files with 22 additions and 7 deletions

View File

@ -103,6 +103,8 @@ pub struct Field {
pub:
name string
// type_idx int
pos token.Position
already_reported bool
mut:
typ table.Type
// typ2 Type

View File

@ -65,20 +65,20 @@ pub fn (x Expr) str() string {
InfixExpr {
return '(${it.left.str()} $it.op.str() ${it.right.str()})'
}
/*
PrefixExpr {
return it.left.str() + it.op.str()
return it.op.str() + it.right.str()
}
*/
IntegerLiteral {
return it.val
}
StringLiteral {
return '"$it.val"'
}
ParExpr {
return it.expr.str()
}
else {
return ''
return '[unhandled expr type ${typeof(x)}]'
}
}
}
@ -113,7 +113,7 @@ pub fn (node Stmt) str() string {
return 'fn ${it.name}() { $it.stmts.len stmts }'
}
else {
return '[unhandled stmt str]'
return '[unhandled stmt str type: ${typeof(node)} ]'
}
}
}

View File

@ -613,7 +613,17 @@ fn (c mut Checker) stmt(node ast.Stmt) {
}
}
if unresolved_num != 0 {
c.error("$unresolved_num ill-defined consts are in use", it.pos)
for i, expr in it.exprs {
typ := c.expr(expr)
if typ == table.void_type {
mut _field := it.fields[i]
if !_field.already_reported {
_field.already_reported = true
it.fields[i] = _field
c.error("$unresolved_num ill-defined const `$_field.name`", _field.pos)
}
}
}
}
for i, field in ordered_fields { // set the fields and exprs as ordered
it.fields[i] = field

View File

@ -1452,6 +1452,7 @@ fn (p mut Parser) const_decl() ast.ConstDecl {
expr := p.expr(0)
fields << ast.Field{
name: name
pos: p.tok.position()
// typ: typ
}
@ -1519,6 +1520,7 @@ fn (p mut Parser) struct_decl() ast.StructDecl {
p.check(.colon)
}
field_name := p.check_name()
field_pos := p.tok.position()
// p.warn('field $field_name')
typ := p.parse_type()
/*
@ -1535,6 +1537,7 @@ fn (p mut Parser) struct_decl() ast.StructDecl {
}
ast_fields << ast.Field{
name: field_name
pos: field_pos
typ: typ
}
fields << table.Field{