V: 1 in [] -> This should never happen

Created on 6 Dec 2019  Â·  5Comments  Â·  Source: vlang/v

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
Bug

All 5 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cjmxp picture cjmxp  Â·  3Comments

lobotony picture lobotony  Â·  3Comments

ArcDrake picture ArcDrake  Â·  3Comments

markgraydev picture markgraydev  Â·  3Comments

radare picture radare  Â·  3Comments