Skip to content

Commit 2c4845a

Browse files
authored
tests: add union_implementing_interface_test.v (#24857)
1 parent 4db6408 commit 2c4845a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
interface Speaker {
2+
speak() string
3+
}
4+
5+
union MyUnion implements Speaker {
6+
vint int
7+
vu32 u32
8+
vstring string
9+
}
10+
11+
fn (u MyUnion) speak() string {
12+
return 'hi, u.vint: ${unsafe { u.vint }}'
13+
}
14+
15+
fn test_union_implementing_interface() {
16+
s := Speaker(MyUnion{
17+
vint: 123
18+
})
19+
assert s.speak() == 'hi, u.vint: 123'
20+
}

0 commit comments

Comments
 (0)