tests: add union_implementing_interface_test.v (#24857)

This commit is contained in:
Delyan Angelov 2025-07-07 00:54:21 +03:00 committed by GitHub
parent 4db6408e0b
commit 2c4845a16f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,20 @@
interface Speaker {
speak() string
}
union MyUnion implements Speaker {
vint int
vu32 u32
vstring string
}
fn (u MyUnion) speak() string {
return 'hi, u.vint: ${unsafe { u.vint }}'
}
fn test_union_implementing_interface() {
s := Speaker(MyUnion{
vint: 123
})
assert s.speak() == 'hi, u.vint: 123'
}