v2 / vlib / v / tests / pointers / ref_array_init_test.v
18 lines · 18 sloc · 525 bytes · 21a0f1117776b7b9b0912e8baea3f4b217aca1e7
Raw
1fn test_reference_array_init() {
2 mut b := &[5, 6, 7]
3 assert '${b}' == '&[5, 6, 7]'
4 mut b_fixed := &[5, 6, 7]!
5 assert '${b_fixed}' == '&[5, 6, 7]'
6 {
7 mut a := [1, 2, 3]
8 // TODO: this should probably produce a notice at least,
9 // (without unsafe{&a}), since it takes the address of something
10 // on the stack, that will very soon be out of scope, even
11 // though it is still in the same function:
12 b = &a
13 b_fixed = &[1, 2, 3]!
14 }
15 println(b)
16 assert '${b}' == '&[1, 2, 3]'
17 assert '${b_fixed}' == '&[1, 2, 3]'
18}
19