From aa39451c8bfe4d6c5ce8ba474db72f5aa77c6f98 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 30 Oct 2019 16:21:57 +0300 Subject: [PATCH] arrays.range(min, max) --- vlib/arrays/arrays.v | 10 ++++++++++ vlib/arrays/arrays_test.v | 10 ++++++++++ vlib/compiler/parser.v | 5 +++-- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 vlib/arrays/arrays.v create mode 100644 vlib/arrays/arrays_test.v diff --git a/vlib/arrays/arrays.v b/vlib/arrays/arrays.v new file mode 100644 index 0000000000..1532a55b11 --- /dev/null +++ b/vlib/arrays/arrays.v @@ -0,0 +1,10 @@ +module arrays + +fn range(start, end T) []T { + mut res := [T(0)] + for i := start; i < end; i++ { + res << i + } + return res +} + diff --git a/vlib/arrays/arrays_test.v b/vlib/arrays/arrays_test.v new file mode 100644 index 0000000000..2fb715a094 --- /dev/null +++ b/vlib/arrays/arrays_test.v @@ -0,0 +1,10 @@ +import arrays + +fn test_range() { + /* + TODO + a := arrays.range(1, 10) + assert a[0] == 1 + println(a) + */ +} diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index 32c016033f..210e558982 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -1641,9 +1641,10 @@ fn (p mut Parser) name_expr() string { p.error('enum `$enum_type.name` does not have value `$val`') } if p.expected_type == enum_type.name { - p.warn('`${enum_type.name}.$val` is unnecessary, use `.$val`') + // `if color == .red` is enough + // no need in `if color == Color.red` + p.error('`${enum_type.name}.$val` is unnecessary, use `.$val`') } - // println('enum val $val') p.gen(mod_gen_name(enum_type.mod) + '__' + enum_type.name + '_' + val)// `color = main__Color_green` p.next()