mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
tests: add as_cast_already_smartcast_sumtype_test.v (#10517)
This commit is contained in:
parent
7ec55e4c51
commit
1a52da9f62
1 changed files with 30 additions and 0 deletions
30
vlib/v/tests/as_cast_already_smartcast_sumtype_test.v
Normal file
30
vlib/v/tests/as_cast_already_smartcast_sumtype_test.v
Normal file
|
@ -0,0 +1,30 @@
|
|||
struct S1 {
|
||||
s1 string = 'abc'
|
||||
}
|
||||
|
||||
struct Empty {
|
||||
}
|
||||
|
||||
type Sum = Empty | S1
|
||||
|
||||
fn test_as_cast_already_smartcast_sumtype() {
|
||||
a := Sum(S1{})
|
||||
if a is S1 {
|
||||
println('if expr: $a.s1')
|
||||
assert a.s1 == 'abc'
|
||||
v1 := a as S1
|
||||
println('if expr (as cast): $v1.s1')
|
||||
assert v1.s1 == 'abc'
|
||||
}
|
||||
|
||||
match a {
|
||||
S1 {
|
||||
println('match expr: $a.s1')
|
||||
assert a.s1 == 'abc'
|
||||
v1 := a as S1
|
||||
println('match expr (as cast): $v1.s1')
|
||||
assert v1.s1 == 'abc'
|
||||
}
|
||||
else {}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue