Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgen: fix member call when arg variable has more than 1 indirection #23423

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
felipensp marked this conversation as resolved.
Show resolved Hide resolved
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
}
Loading