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

v2: checker: fix --/++

This commit is contained in:
Alexander Medvednikov 2020-02-27 17:31:10 +01:00
parent 09b7a7c872
commit 3bde876097
3 changed files with 12 additions and 4 deletions

View File

@ -633,8 +633,10 @@ pub fn (c mut Checker) postfix_expr(node ast.PostfixExpr) table.Type {
}
*/
typ := c.expr(node.expr)
if !table.is_number(typ) {
typ_sym := c.table.get_type_symbol(typ)
typ_sym := c.table.get_type_symbol(typ)
// if !table.is_number(typ) {
if !typ_sym.is_number() {
println(typ_sym.kind.str())
c.error('invalid operation: $node.op.str() (non-numeric type `$typ_sym.name`)', node.pos)
}
return typ

View File

@ -799,6 +799,7 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) {
node = ast.PostfixExpr{
op: p.tok.kind
expr: node
pos: p.tok.position()
}
p.next()
return node,typ

View File

@ -101,10 +101,15 @@ pub const (
number_idxs = [int_type_idx, byte_type_idx, u64_type_idx]
)
/*
pub fn is_number(typ Type) bool {
idx := type_idx(typ)
return idx in [int_type_idx, byte_type_idx, u64_type_idx]
typ_sym := c.table.get_type_symbol(typ)
return typ_sym.is_int()
//idx := type_idx(typ)
//return idx in [int_type_idx, byte_type_idx, u64_type_idx]
}
*/
pub const (
void_type = new_type(void_type_idx)