diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 91895d3f25..6b12b397e7 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -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 diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index 1e48b2844b..ecfbf6c3f5 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -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)} ]' } } } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index b77d19e0ca..4b68c8e9a1 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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 diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index d36e13d07a..9630be02f6 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -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{