1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

test: add match sumtype var shadow and as test

This commit is contained in:
joe-conigliaro 2020-06-19 01:06:40 +10:00
parent 45239cbd62
commit 3533335804
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1

View File

@ -0,0 +1,31 @@
struct Cat{name string}
struct Dog{name string}
type Animal = Cat | Dog
fn main() {
cat := Cat{name: 'cat'}
dog := Cat{name: 'dog'}
mut animal := Animal{}
// test shaddow
animal = cat
match animal {
Cat {
assert animal.name == cat.name
}
else{
assert false
}
}
// test as
animal = dog
match animal as animal_kind {
Dog {
assert animal_kind.name == dog.name
}
else{
assert false
}
}
}