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

arrays.range(min, max)

This commit is contained in:
Alexander Medvednikov 2019-10-30 16:21:57 +03:00
parent 96f7620628
commit aa39451c8b
3 changed files with 23 additions and 2 deletions

10
vlib/arrays/arrays.v Normal file
View File

@ -0,0 +1,10 @@
module arrays
fn range<T>(start, end T) []T {
mut res := [T(0)]
for i := start; i < end; i++ {
res << i
}
return res
}

10
vlib/arrays/arrays_test.v Normal file
View File

@ -0,0 +1,10 @@
import arrays
fn test_range() {
/*
TODO
a := arrays.range(1, 10)
assert a[0] == 1
println(a)
*/
}

View File

@ -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()