v2: postfix_expr() checker

pull/3646/head
Alexander Medvednikov 2020-02-04 07:37:38 +01:00
parent 4d6958381d
commit c7f07cd0b6
2 changed files with 18 additions and 1 deletions

View File

@ -235,6 +235,7 @@ pub struct PostfixExpr {
pub:
op token.Kind
expr Expr
pos token.Position
}
pub struct PrefixExpr {

View File

@ -242,7 +242,7 @@ pub fn (c &Checker) expr(node ast.Expr) table.Type {
}
// ast.FloatLiteral {}
ast.PostfixExpr {
return c.expr(it.expr)
return c.postfix_expr(it)
}
/*
ast.UnaryExpr {
@ -309,6 +309,22 @@ pub fn (c &Checker) expr(node ast.Expr) table.Type {
return table.void_type
}
pub fn (c &Checker) postfix_expr(node ast.PostfixExpr) table.Type {
/*
match node.expr {
ast.IdentVar {
println('postfix identvar')
}
else {}
}
*/
typ := c.expr(node.expr)
if typ.kind != .int {
c.error('invalid operation: $node.op.str() (non-numeric type `$typ.name`)', node.pos)
}
return typ
}
pub fn (c &Checker) index_expr(node ast.IndexExpr) table.Type {
mut typ := c.expr(node.left)
mut is_range := false // TODO is_range := node.index is ast.RangeExpr