V version: V 0.1.23 b8ab85e
OS: Debian 9.11
What did you do?
I typed the following into the V REPL:
1 in []
What did you expect to see?
false
What did you see instead?
$ v
V 0.1.23 b8ab85e
Use Ctrl-C or `exit` to exit
>>> 1 in []
/tmp/v/.vrepl_temp.tmp.c: In function ‘main’:
/tmp/v/.vrepl_temp.tmp.c:3318:3: warning: statement with no effect [-Wunused-value]
1 ) ;
^
/tmp/v/.vrepl_temp.tmp.c:3318:5: error: expected ‘;’ bef...
(Use `v -g` to print the entire error message)
V error: C error. This should never happen.
Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose
This works:
``shell
$ ./v
V 0.1.23 867f952
Use Ctrl-C orexit` to exit
empty_ints_list := []int
println( 1 in empty_ints_list )
false```
I thinkx in []` should either produce a v compiler error, or should be special cased to return always false ?
Fixed:
`x in []` is always false
And what does [] mean in V? It's an array literal of undefined type. So this should never compile in V.
And whenever in real life would you use x in []? As it was said:
empty_ints_list := []int
println( 1 in empty_ints_list )
works fine. And that's what is needed. Even 1.0 in empty_ints_list should not compile because of the type missmatch. But what is [] in a strict typed language?
a := []
Should never compile, as the type is not specified.
What is possible is
a := []int
And later you can assign a = []
as the type is known.
x in []
I assume in the above case [] is just inferred to be the type of x