From c7f07cd0b6a0f44dc73e3c1c269a9d5c1f430136 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 4 Feb 2020 07:37:38 +0100 Subject: [PATCH] v2: postfix_expr() checker --- vlib/v/ast/ast.v | 1 + vlib/v/checker/checker.v | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 951e746763..1246f6331a 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -235,6 +235,7 @@ pub struct PostfixExpr { pub: op token.Kind expr Expr + pos token.Position } pub struct PrefixExpr { diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 7a20eaa0ac..13c3cd04dd 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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