mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix immutable deref check
This commit is contained in:
parent
88f89bde4e
commit
83afa1009e
@ -707,7 +707,12 @@ fn (mut c Checker) fail_if_immutable(expr_ ast.Expr) (string, token.Pos) {
|
|||||||
to_lock, pos = c.fail_if_immutable(expr.expr)
|
to_lock, pos = c.fail_if_immutable(expr.expr)
|
||||||
}
|
}
|
||||||
ast.PrefixExpr {
|
ast.PrefixExpr {
|
||||||
to_lock, pos = c.fail_if_immutable(expr.right)
|
if expr.op == .mul && expr.right is ast.Ident {
|
||||||
|
// Do not fail if dereference is immutable:
|
||||||
|
// `*x = foo()` doesn't modify `x`
|
||||||
|
} else {
|
||||||
|
to_lock, pos = c.fail_if_immutable(expr.right)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ast.PostfixExpr {
|
ast.PostfixExpr {
|
||||||
to_lock, pos = c.fail_if_immutable(expr.expr)
|
to_lock, pos = c.fail_if_immutable(expr.expr)
|
||||||
|
0
vlib/v/checker/tests/immutable_deref.out
Normal file
0
vlib/v/checker/tests/immutable_deref.out
Normal file
12
vlib/v/checker/tests/immutable_deref.vv
Normal file
12
vlib/v/checker/tests/immutable_deref.vv
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
struct Context {}
|
||||||
|
|
||||||
|
const ctx_ptr = &Context(unsafe { nil })
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// TODO unsafe bug, having this declaration inside `unsafe` results in an erro
|
||||||
|
x := &ctx_ptr
|
||||||
|
unsafe {
|
||||||
|
*x = &Context{}
|
||||||
|
_ = x
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user