test: add match sumtype var shadow and `as` test

pull/5416/head
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
1 changed files with 31 additions and 0 deletions

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
}
}
}