Skip to content

Commit bb91dc9

Browse files
authored
checker: fix & on pointers (#6787)
1 parent baf2ff1 commit bb91dc9

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

vlib/v/checker/checker.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,6 +2856,8 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
28562856
}
28572857
}
28582858
return right_type.to_ptr()
2859+
} else if node.op == .amp && node.right !is ast.CastExpr {
2860+
return right_type.to_ptr()
28592861
}
28602862
if node.op == .mul {
28612863
if right_type.is_ptr() {

vlib/v/tests/unsafe_test.v

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@ fn test_ptr_assign() {
1414
assert v[3] == 31
1515
}
1616

17+
fn test_double_ptr() {
18+
i := 5
19+
j := 7
20+
unsafe {
21+
mut x := &i
22+
mut p := &x
23+
(*p) = &j
24+
assert x == &j
25+
}
26+
27+
/////////
28+
29+
mut x := &int(0)
30+
unsafe {
31+
mut p := &x
32+
(*p) = &int(1)
33+
}
34+
assert ptr_str(x) == ptr_str(&int(1))
35+
}
36+
1737
fn test_ptr_infix() {
1838
v := 4
1939
mut q := unsafe {&v - 1}

0 commit comments

Comments
 (0)