1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

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

This commit is contained in:
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: pub:
name string name string
// type_idx int // type_idx int
pos token.Position
already_reported bool
mut: mut:
typ table.Type typ table.Type
// typ2 Type // typ2 Type

View File

@ -65,20 +65,20 @@ pub fn (x Expr) str() string {
InfixExpr { InfixExpr {
return '(${it.left.str()} $it.op.str() ${it.right.str()})' return '(${it.left.str()} $it.op.str() ${it.right.str()})'
} }
/*
PrefixExpr { PrefixExpr {
return it.left.str() + it.op.str() return it.op.str() + it.right.str()
} }
*/
IntegerLiteral { IntegerLiteral {
return it.val return it.val
} }
StringLiteral { StringLiteral {
return '"$it.val"' return '"$it.val"'
} }
ParExpr {
return it.expr.str()
}
else { 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 }' return 'fn ${it.name}() { $it.stmts.len stmts }'
} }
else { 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 { 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 for i, field in ordered_fields { // set the fields and exprs as ordered
it.fields[i] = field it.fields[i] = field

View File

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