v
v copied to clipboard
parser?: smart casting on array's element
OS: macos, macOS, 12.4, 21F79
Processor: 8 cpus, 64bit, little endian, Apple M1
CC version: Apple clang version 13.1.6 (clang-1316.0.21.2.5)
getwd: /Users/hunam/Documents/dev/go2v
vmodules: /Users/hunam/.vmodules
vroot: /Applications/v
vexe: /Applications/v/v
vexe mtime: 2022-06-15 20:51:24
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.4 0eb3f88.2052210
Git version: git version 2.32.1 (Apple Git-133)
Git vroot status: weekly.2022.22-111-g20522107-dirty
.git/config present: true
thirdparty/tcc status: thirdparty-macos-arm64 173c526e
What did you do?
type SumType = int | string
fn main() {
arr := [SumType(1)]
if arr[0] is int {
accept_int(arr[0]) // doesn't work
}
el := SumType(1)
if el is int {
accept_int(el) // works
}
}
fn accept_int(x int) {}
What did you see instead?
a.v:6:14: error: cannot use `SumType` as `int` in argument 1 to `accept_int`
4 | arr := [SumType(1)]
5 | if arr[0] is int {
6 | accept_int(arr[0]) // doesn't work
| ~~~~~~
7 | }
8 |
Both cases should work the same.