V version: V 0.1.29 9fdf04b.e250547
OS: Windows 7 Professional (x64, little-endian)
CC version: clang version 10.0.0 (https://github.com/llvm/llvm-project.git d32170dbd5b0d54436537b6b75beaf44324e0c28)
What did you do?
fn optional_arg(x ?int) {
println("int type")
}
fn main() {
optional_arg(1)
}
What did you expect to see?
I expected V to either to throw an error for unable to convert between any_int to option_int or convert the corresponding type to its option counterpart
What did you see instead?
C:\Users\lambda\AppData\Local\Temp\v\hello_world.1829071214341309535.tmp.c:8082:21: error: passing 'int' to parameter of incompatible type 'Option_int' (aka 'struct Option_int')
main__optional_arg(1);
^
C:\Users\lambda\AppData\Local\Temp\v\hello_world.1829071214341309535.tmp.c:8077:36: note: passing argument to parameter 'x' here
void main__optional_arg(Option_int x) {
^
9 warnings and 1 error generated.
ATM V forces you to unwrap an optional produced by a function without assigning it to a variable. I think optionals should be a first class type, so your example should work too.
Thanks for taking a look at this ntrel. Sorry for my ignorance, but could you elaborate on what unwrapping an optional means?
?int(1)
Yes, this example should compile.
Hi Alex, I tested ?int(1) with a fresh copy of V with the latest changes from master, but it threw a bad token error
edit:
Sorry i think i misunderstood what you meant by ?int, yeah so i need a function to return an optional, something like optional_arg(option_int(1)) where option_int just returns an option int type. Thanks!
Indeed, it's not implemented. I thought it was :)
Another thing to fix.
Most helpful comment
ATM V forces you to unwrap an optional produced by a function without assigning it to a variable. I think optionals should be a first class type, so your example should work too.