Skip to content

Instantly share code, notes, and snippets.

@endeveit
Created July 23, 2020 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save endeveit/3494cd8bf093bc7a2d026fd9a0cc4baf to your computer and use it in GitHub Desktop.
Save endeveit/3494cd8bf093bc7a2d026fd9a0cc4baf to your computer and use it in GitHub Desktop.
module main
type Number = any_int | any_float
fn is_gt(val string, dst Number) bool {
match dst {
any_int {
return val.int() > dst
}
any_float {
return val.f64() > dst
}
}
}
fn main() {
rs := is_gt('3', 2)
println(rs)
}
@endeveit
Copy link
Author

here's the output:

$ v run main.v
==================
                       ~~~~~~~~~~~~~~~ ^ ~~~
/private/var/folders/4z/zkxqxv9n545dgkx16_d5zhmm0000gn/T/v/main.tmp.c:9414:26: error: invalid operands to binary expression ('f64' (aka 'double') and 'any_float *' (aka 'double *'))
                return string_f64(val) > dst;
                       ~~~~~~~~~~~~~~~ ^ ~~~
/private/var/folders/4z/zkxqxv9n545dgkx16_d5zhmm0000gn/T/v/main.tmp.c:9446:38: warning: integer literal is too large to be represented in a signed integer type, interpreting as unsigned [-Wimplicitly-unsigned-literal]
        _const_math__bits__max_u64 = ((u64)(18446744073709551615));
                                            ^
/private/var/folders/4z/zkxqxv9n545dgkx16_d5zhmm0000gn/T/v/main.tmp.c:9473:409: warning: integer literal is too large to be represented in a signed integer type, interpreting as unsigned [-Wimplicitly-unsigned-literal]
                ((u64)(1)), ((u64)(10)), ((u64)(100)), ((u64)(1000)), ((u64)(10000)), ((u64)(100000)), ((u64)(1000000)), ((u64)(10000000)), ((u64)(100000000)), ((u64)(1000000000)), ((u64)(10000000000)), ((u64)(100000000000)), ((u64)(1000000000000)), ((u64)(10000000000000)), ((u64)(100000000000000)), ((u64)(1000000000000000)), ((u64)(10000000000000000)), ((u64)(100000000000000000)), ((u64)(1000000000000000000)), ((u64)(10000000000000000000))}));
                                                                                                                                                                                                                                                                                                                                                                                                                                      ^
24 warnings and 1 error generated.
...
==================
(Use `v -cg` to print the entire error message)

builder error:
==================
C error. This should never happen.

If you were not working with C interop, please raise an issue on GitHub:

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment