cgen: fix codegen for interface method call which returns a fixed array (fix #22326) (#22331)

This commit is contained in:
Felipe Pena 2024-09-27 11:32:53 -03:00 committed by GitHub
parent 6ba87b948a
commit 2afce42fc7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 0 deletions

View File

@ -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)

View File

@ -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
}