You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a closure captures a variable by mut whose type is an alias of a pointer (type AppRef = &App), cgen stores the capture in the closure context struct as a double pointer (AppRef* app;, i.e. App**), but the closure body emits only a single dereference (_V_closure_ctx->app->field). The C compiler then rejects the member access because _V_closure_ctx->app is itself a pointer.
A non-mut capture of the same alias compiles correctly, which isolates the extra (unaccounted-for) pointer level to the mut capture path.
V version: V 0.5.1, current master (5e36217f8) OS/Backend: reproduced on macOS arm64; originally reported on Linux (a _V_closure_ctx->app member-reference error from a captured pointer).
error: member reference base type 'main__AppRef' (aka 'struct main__App *') is not a structure or union
_V_closure_ctx->app->score++;
The generated context struct field is main__AppRef* app; (a struct main__App **), but the body accesses it as _V_closure_ctx->app->score (one deref short). It should be either (*_V_closure_ctx->app)->score, or the field should be stored as main__AppRef (single pointer).
Expected behavior
The captured-pointer member access in the closure body should match the pointer level of the context-struct field, so the program compiles.
Notes
Reported via the bugs.vlang.io crash reporter (a '_V_closure_ctx->app' is a pointer; did you mean to use '->'? variant from a captured pointer in a closure). This reproducer is the same closure-captured-pointer member-access family; the operator/pointer-level mismatch direction differs.
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
Description
When a closure captures a variable by
mutwhose type is an alias of a pointer (type AppRef = &App), cgen stores the capture in the closure context struct as a double pointer (AppRef* app;, i.e.App**), but the closure body emits only a single dereference (_V_closure_ctx->app->field). The C compiler then rejects the member access because_V_closure_ctx->appis itself a pointer.A non-
mutcapture of the same alias compiles correctly, which isolates the extra (unaccounted-for) pointer level to themutcapture path.V version: V 0.5.1, current
master(5e36217f8)OS/Backend: reproduced on macOS arm64; originally reported on Linux (a
_V_closure_ctx->appmember-reference error from a captured pointer).Reproducer
Compile with:
Current behavior
The generated context struct field is
main__AppRef* app;(astruct main__App **), but the body accesses it as_V_closure_ctx->app->score(one deref short). It should be either(*_V_closure_ctx->app)->score, or the field should be stored asmain__AppRef(single pointer).Expected behavior
The captured-pointer member access in the closure body should match the pointer level of the context-struct field, so the program compiles.
Notes
'_V_closure_ctx->app' is a pointer; did you mean to use '->'?variant from a captured pointer in a closure). This reproducer is the same closure-captured-pointer member-access family; the operator/pointer-level mismatch direction differs.Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.