From 92e3e48bce50468e96ad9a113aaf1a35d1d535c9 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 19 Feb 2020 21:13:42 +0100 Subject: [PATCH] v2: checker: [] and in --- vlib/v/checker/checker.v | 8 ++++++-- vlib/v/table/table.v | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 181c4d3a75..2fb693f3df 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -93,11 +93,15 @@ pub fn (c mut Checker) infix_expr(infix_expr ast.InfixExpr) table.Type { if !c.table.check(right_type, left_type) { left := c.table.get_type_symbol(left_type) right := c.table.get_type_symbol(right_type) - // array << elm + // `array << elm` // the expressions have different types (array_x and x) if left.kind == .array && infix_expr.op == .left_shift { return table.void_type } + // `elm in array` + if right.kind == .array && infix_expr.op == .key_in { + return table.bool_type + } // if !c.table.check(&infix_expr.right_type, &infix_expr.right_type) { // c.error('infix expr: cannot use `$infix_expr.right_type.name` as `$infix_expr.left_type.name`', infix_expr.pos) c.error('infix expr: cannot use `$right.name` (right) as `$left.name`', infix_expr.pos) @@ -378,7 +382,7 @@ pub fn (c mut Checker) expr(node ast.Expr) table.Type { return it.typ } ast.None { - return table.none_type + return table.none_type } else {} } diff --git a/vlib/v/table/table.v b/vlib/v/table/table.v index 267cdcd581..777c3b1f0e 100644 --- a/vlib/v/table/table.v +++ b/vlib/v/table/table.v @@ -395,6 +395,11 @@ pub fn (t &Table) check(got, expected Type) bool { if exp_type_sym.name == 'array' || got_type_sym.name == 'array' { return true } + // TODO + // accept [] when an expected type is an array + if got_type_sym.kind == .array && got_type_sym.name == 'array_void' && exp_type_sym.kind == .array { + return true + } if got_idx != exp_idx { // && got.typ.name != expected.typ.name*/ return false