From 856b923cc9ec4c0628f094eae6fd735ab5c5a669 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 14 Apr 2026 12:45:35 +0300 Subject: [PATCH] checker: comparing interface with struct instance gives c error: invalid operand types for binary operation, invalid aggregate type for register load (fixes #24018) --- .../tests/interface_struct_comparison_err.out | 14 ++++++++ .../tests/interface_struct_comparison_err.vv | 36 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 vlib/v/checker/tests/interface_struct_comparison_err.out create mode 100644 vlib/v/checker/tests/interface_struct_comparison_err.vv diff --git a/vlib/v/checker/tests/interface_struct_comparison_err.out b/vlib/v/checker/tests/interface_struct_comparison_err.out new file mode 100644 index 000000000..7042f48ba --- /dev/null +++ b/vlib/v/checker/tests/interface_struct_comparison_err.out @@ -0,0 +1,14 @@ +vlib/v/checker/tests/interface_struct_comparison_err.vv:22:30: error: `?IGameObject` cannot be used as `GameObject`, unwrap the option first + 20 | fn (mut gameobject GameObject) collision(mut o IGameObject) { + 21 | _ = o + 22 | if gameobject != gameobject.owner { + | ~~~~~ + 23 | eprintln('Collision') + 24 | } +vlib/v/checker/tests/interface_struct_comparison_err.vv:22:5: error: infix expr: cannot use `IGameObject` (right expression) as `GameObject` + 20 | fn (mut gameobject GameObject) collision(mut o IGameObject) { + 21 | _ = o + 22 | if gameobject != gameobject.owner { + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 23 | eprintln('Collision') + 24 | } diff --git a/vlib/v/checker/tests/interface_struct_comparison_err.vv b/vlib/v/checker/tests/interface_struct_comparison_err.vv new file mode 100644 index 000000000..0af88af13 --- /dev/null +++ b/vlib/v/checker/tests/interface_struct_comparison_err.vv @@ -0,0 +1,36 @@ +module main + +@[heap] +interface IGameObject { +mut: + name string + speed f32 + owner ?&IGameObject + collision(mut o IGameObject) +} + +@[heap] +struct GameObject implements IGameObject { +mut: + name string + speed f32 + owner ?&IGameObject +} + +fn (mut gameobject GameObject) collision(mut o IGameObject) { + _ = o + if gameobject != gameobject.owner { + eprintln('Collision') + } +} + +fn main() { + mut ship := &GameObject{ + name: 'ship' + } + mut rocket := &GameObject{ + name: 'rocket' + owner: ship + } + rocket.collision(mut ship) +} -- 2.39.5