mirror of
https://github.com/vlang/v.git
synced 2025-09-16 02:49:31 -04:00
parent
44f8ba6161
commit
6b31c86fea
@ -2639,7 +2639,7 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
|
||||
&& g.table.unaliased_type(arg_typ).is_pointer() && expected_type.is_pointer()) {
|
||||
if arg.is_mut {
|
||||
if exp_sym.kind == .array {
|
||||
if (arg.expr is ast.Ident && arg.expr.kind == .variable)
|
||||
if (arg.expr is ast.Ident && arg.expr.kind in [.global, .variable])
|
||||
|| arg.expr is ast.SelectorExpr {
|
||||
g.write('&')
|
||||
g.expr(arg.expr)
|
||||
|
24
vlib/v/tests/global_init_array_test.v
Normal file
24
vlib/v/tests/global_init_array_test.v
Normal file
@ -0,0 +1,24 @@
|
||||
@[has_globals]
|
||||
module main
|
||||
|
||||
struct Rectangle {
|
||||
x int
|
||||
y int
|
||||
w int
|
||||
h int
|
||||
}
|
||||
|
||||
__global bricks = []Rectangle{}
|
||||
|
||||
fn init_bricks(mut bricks []Rectangle) {
|
||||
for i in 0 .. 5 {
|
||||
bricks << Rectangle{i, 2 * i, 3 * i, 4 * i}
|
||||
}
|
||||
dump(bricks.len)
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
assert bricks.len == 0
|
||||
init_bricks(mut bricks)
|
||||
assert bricks.len == 5
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user