checker: fix `&` on pointers (#6787)

pull/6816/head
spaceface777 2020-11-10 12:12:21 +01:00 committed by GitHub
parent baf2ff1a91
commit bb91dc90a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -2856,6 +2856,8 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
}
}
return right_type.to_ptr()
} else if node.op == .amp && node.right !is ast.CastExpr {
return right_type.to_ptr()
}
if node.op == .mul {
if right_type.is_ptr() {

View File

@ -14,6 +14,26 @@ fn test_ptr_assign() {
assert v[3] == 31
}
fn test_double_ptr() {
i := 5
j := 7
unsafe {
mut x := &i
mut p := &x
(*p) = &j
assert x == &j
}
/////////
mut x := &int(0)
unsafe {
mut p := &x
(*p) = &int(1)
}
assert ptr_str(x) == ptr_str(&int(1))
}
fn test_ptr_infix() {
v := 4
mut q := unsafe {&v - 1}