From 2c4845a16f00c486594e051793aee2e82282ba03 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 7 Jul 2025 00:54:21 +0300 Subject: [PATCH] tests: add union_implementing_interface_test.v (#24857) --- .../union_implementing_interface_test.v | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 vlib/v/tests/unions/union_implementing_interface_test.v diff --git a/vlib/v/tests/unions/union_implementing_interface_test.v b/vlib/v/tests/unions/union_implementing_interface_test.v new file mode 100644 index 0000000000..00134d4768 --- /dev/null +++ b/vlib/v/tests/unions/union_implementing_interface_test.v @@ -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' +}