Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 10, 2025
1 parent 6348e58 commit db57c0d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions vlib/v/gen/c/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,15 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
g.write('(*(${g.styp(fn_typ)}*)')
}
}
needs_deref := node.left_type.nr_muls() > 1
if needs_deref {
g.write('(')
g.write('*'.repeat(node.left_type.nr_muls() - 1))
}
g.expr(node.left)
if needs_deref {
g.write(')')
}
if node.left_type.is_ptr() {
g.write('->')
} else {
Expand Down
43 changes: 43 additions & 0 deletions vlib/v/tests/fns/call_member_from_ptr_ptr_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import gg

pub type WindowResizeFn = fn (window &Window, w int, h int)

@[heap]
pub struct Window {
id string = '_window_'
pub mut:
resize_fn WindowResizeFn = unsafe { nil }
}

@[params]
pub struct WindowParams {
pub:
on_resize WindowResizeFn = unsafe { nil }
}

fn window_resized(event gg.Event, mut w &Window) {
window_width, window_height := 200, 100

if w.resize_fn != WindowResizeFn(0) {
w.resize_fn(w, window_width, window_height)
}
}

fn on_event(e &gg.Event, mut w Window) {
window_resized(e, mut w)
}

fn on_resize(window &Window, w int, h int) {
assert w == 200
assert h == 100
}

fn test_main() {
e := gg.Event{}
mut w := &Window{
resize_fn: on_resize
}

on_event(e, mut w)
assert true
}

0 comments on commit db57c0d

Please sign in to comment.