Skip to content

Commit

Permalink
cgen: fix codegen for interface method call which returns a fixed arr…
Browse files Browse the repository at this point in the history
…ay (fix #22326) (#22331)
  • Loading branch information
felipensp committed Sep 27, 2024
1 parent 6ba87b9 commit 2afce42
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions vlib/v/gen/c/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,11 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
g.call_args(node)
}
g.write(')')
if !node.return_type.has_option_or_result() {
if g.table.final_sym(node.return_type).kind == .array_fixed {
g.write('.ret_arr')
}
}
return
}
left_sym := g.table.sym(left_type)
Expand Down
41 changes: 41 additions & 0 deletions vlib/v/tests/fns/iface_method_fixed_arr_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module main

pub type Mat4 = [16]f32

pub fn (a Mat4) * (b Mat4) Mat4 {
mut res := Mat4{}
for i := 0; i < 4; i++ {
for j := 0; j < 4; j++ {
res[j * 4 + i] = 0
for k := 0; k < 4; k++ {
res[j * 4 + i] += a[k * 4 + i] * b[j * 4 + k]
}
}
}
return res
}

interface IGameObject {
parent ?&IGameObject
transform Mat4
world_transform() Mat4
}

struct GameObject implements IGameObject {
mut:
transform Mat4
parent ?&IGameObject
}

fn (gameobject GameObject) world_transform() Mat4 {
if mut p := gameobject.parent {
return p.world_transform() * gameobject.transform
}
return gameobject.transform
}

fn test_main() {
t := GameObject{}
a := dump(t.world_transform())
assert a.len == 16
}

0 comments on commit 2afce42

Please sign in to comment.